Android2014.06.09 14:18




이번에 스마트 스위치를 릴리즈 했습니다.

기본 기능은 AP의 BSSID를 인식하여 스마트폰의 볼륨과 비행기모드를 자동으로 조정해주는 기능입니다. 이런 기능의 앱은 여러개가 있지만 간략하게 볼륨 조정에 필요한 기능만 넣어서 누구나 직관적으로 쉽게 사용할 수 있도록 하였습니다. 사용법에 대한 유튜브 동영상입니다. 사용에 참고하세요.

 

 

Smart Switch / Android




Posted by 금붕어70
Android2014.06.03 09:38




짬짬히 개발하고 있는 Smart Switch를 이미 이전에 개발을 한 분이 있군요. 그리고 지금 제가 느끼고 있는 문제도 해결해 놓았습니다. 다른 부연 설명은 하지 않고 정말로 좋은 아이디어 인것 같아 올립니다.

http://goltermann.cc/2011/11/android-accessing-wifi-even-in-standby-using-wakelock-wifilock-alarmmanager-and-services/

Android: Accessing Wifi even in Standby using WakeLock, WifiLock, Alarmmanager and Services

I wrote a little App to switch my phone in silent mode automatically as soon as a specific Wifi Network comes in range. I had some problems with using the wireless after the phone was gone into standby. Here is what I did and how to solve the problems I had with the standby mode.

My first attempt to do this was to register a BroadcastReceiver that listens on WifiManager.SCAN_RESULTS_AVAILABLE_ACTION Events. This event is fired as soon as the Android OS completes a Wlan scan, which is done approximately every ten to twenty seconds. The program than checks whether a certain SSID is in the results and silences the phone if it is the case. Here is the short version of the code:

public class WifiStateReciever extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		// Proceed only if received action is a wlan scan result
		if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(intent.getAction())) {

			// get List of networks in reach
			WifiManager connManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
			List<ScanResult> scanResults = connManager.getScanResults();

			// get list of silenced networks from preferences
			for(int i=0;i<scanResults.size();i++) {
				// if network is in in preferences and is checked then silence the phone
				if( ... certain network is this network ...) {
					mAudio.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
					return;
				}
			}
		}
	}
}

Here is the corresponding manifest entry:

	
<receiver android:name="WifiStateReciever">
	<intent-filter>
		<action android:name="android.net.wifi.SCAN_RESULTS"></action>
	</intent-filter>
</receiver>
	

Problem:

The problem with this is that it stops working as soon as the phone goes into standby. My phone goes into standby 15 minutes after turning off the screen. CPU and Wifi is stopped during standby, only GSM is operating for incoming calls and a few other things. So my phone will not notice any new wireless network and hence not go into silent mode. So this way my app is missing the point.

Solution 1:

Fortunately there are ways to make this work. The simplest one is to prevent the phone from going into standby. (DO NOT DO THIS! Read on to see why and see the correct version below) This can be achieved using WakeLock and WifiLock. A WakeLock prevents the CPU, A WifiLock the Wlan from going into standby until they are released. Both are needed to get scan results from the phone all the time, even when it would be in standby. To hold these locks all the time you can use a service that is created as soon as the phone boots, acquire the locks in the onCreate() method and only release them in the onDestroy() method (the latter should only occur if the phone shuts down)

public class StartupReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		Intent serviceIntent = new Intent();
		serviceIntent.setAction("de.goltergaul.wlanSilence.WlanLockService");
		context.startService(serviceIntent);
	}

}

public class WlanLockService extends Service {

	private WifiLock wifiLock;
	private WakeLock wakeLock;

	@Override
	public IBinder onBind(Intent arg0) {
		return null;
	}

	@Override
	public void onCreate() {
		super.onCreate();

		WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
		wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL , "MyWifiLock");
		wifiLock.acquire();

		PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
		wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Lock");
		wakeLock.acquire();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();

		wifiLock.release();
		wakeLock.release();
	}
}

			
			
		

Here is the corresponding manifest entry:

<receiver android:name="StartupReceiver">
	<intent-filter>
		<action android:name="android.intent.action.BOOT_COMPLETED" />
		<category android:name="android.intent.category.HOME" />
	</intent-filter>
</receiver>
<service android:name="WlanLockService">
	<intent-filter>
		<action android:name="de.goltergaul.wlanSilence.WlanLockService" />
	</intent-filter>
</service>	
	

The downside of this approach is that it consumes a huge amount of extra energy because you eliminate the standby mode completely.screenshot-1320755332329 The figure on the right is showing the energy consumption of all processes. WlanSilncer is the application preventing the standby mode. Therefore this is not the way to do it!

Solution 2:

The second option is to use the Android AlarmManager. That is a service that can wake up the phone after a certain period of time, execute an PendingIntent (A block of code) and then go to sleep again. This way the the phone can go into standby and just wakes up to scan for new wireless networks and goes to sleep again right after that. This way is much more energy efficient. To implement this I wrote another BroadcastReceiver which receives events from the AlarmManager:

	
public class WlanScanner extends BroadcastReceiver {

	private AlarmManager alarmMgr;
	private PendingIntent pendingIntent;

	private static WifiLock wifiLock;
	private static WakeLock wakeLock;

	public static void lock() {
		try {
			wakeLock.acquire();
			wifiLock.acquire();
		} catch(Exception e) {
			Log.e("WlanSilencer", "Error getting Lock: "+e.getMessage());
		}
	}

	public static void unlock() {
		if(wakeLock.isHeld())
			wakeLock.release();
		if(wifiLock.isHeld())
			wifiLock.release();
	}

	public WlanScanner() {} // called by the AlarmManager

	// this constructor is invoked by WlanLockService (see next code snippet)
	public WlanScanner(Context context, int timeoutInSeconds){

		// initialise the locks
		wifiLock = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE))
						.createWifiLock(WifiManager.WIFI_MODE_SCAN_ONLY , "WlanSilencerScanLock");
		wakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE))
						.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WlanSilencerWakeLock");

        	alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

		// use this class as the receiver
        	Intent intent = new Intent(context, WlanScanner.class);
        	// create a PendingIntent that can be passed to the AlarmManager
        	pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        	// create a repeating alarm, that goes of every x seconds
        	// AlarmManager.ELAPSED_REALTIME_WAKEUP = wakes up the cpu only
       		alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), timeoutInSeconds*1000, pendingIntent);
	}

	// stop the repeating alarm
	public void stop() {
		alarmMgr.cancel(pendingIntent);
	}

	@Override
	public void onReceive(Context context, Intent arg1) {
		Log.v("WlanSilencer", "Alarm received");
		WifiManager connManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
		if(connManager.isWifiEnabled()) {
			lock(); // lock wakeLock and wifiLock, then scan.
			// unlock() is then called at the end of the onReceive function of WifiStateReciever
			connManager.startScan();
		}
	}

}

	
	
public class WlanLockService extends Service {

	private WlanScanner scanner;

	@Override
	public IBinder onBind(Intent arg0) {
		return null;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		scanner = new WlanScanner(this, 60);
	}

	@Override
	public void onDestroy() {
		super.onDestroy();

		scanner.stop();
		scanner = null;
	}
}

	

Summary:

The code has to do this in the right order:

  1. After the device booted the WlanLockService has to be started
  2. The WlanLockService has to initialize WlanScanner which sets a repeated Alarm using the AlarmManager
  3. Once the alarm is received a WakeLock and a WifiLock should be acquired
  4. A wlan scan can now be requested
  5. The wlan scan result event is received and processed
  6. Release the WakeLock and WifiLock




Posted by 금붕어70
Android2011.04.11 17:27





다른 블로그를 보고 간단한 설명만 되어 있어서 어떻게 구현해야 하나 고민하다가 구현해본 소스입니다.
개발에 참고 하세요.

1. chart_demo.xml


	
	


2. ChartDemoActivity.java
public class ChartDemoActivity extends Activity {

	private final static String TAG = ChartDemoActivity.class.getSimpleName();
	private GraphicalView mChartView;
	private XYMultipleSeriesRenderer mRenderer;
	private XYMultipleSeriesDataset mDataset;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.chart_demo);
		mDataset = buildDataset();
		mRenderer = buildRenderer();
	}

	@Override
	protected void onResume() {
		super.onResume();
		if (mChartView == null) {
			LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
			mChartView = ChartFactory.getLineChartView(this, mDataset, mRenderer);
			layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		} else {
			mChartView.repaint();
		}

	}

	private static final long HOUR = 3600 * 1000;
	private static final long DAY = HOUR * 24;
	private static final int HOURS = 24;
	private List x = null;

	private XYMultipleSeriesDataset buildDataset() {
		String[] titles = new String[] { "Inside", "Outside" };
		long now = Math.round(new Date().getTime() / DAY) * DAY;
		x = new ArrayList();
		for (int i = 0; i < titles.length; i++) {
			Date[] dates = new Date[HOURS];
			for (int j = 0; j < HOURS; j++) {
				dates[j] = new Date(now - (HOURS - j) * HOUR);
			}
			x.add(dates);
		}
		List values = new ArrayList();

		values.add(new double[] { 21.2, 21.5, 21.7, 21.5, 21.4, 21.4, 21.3, 21.1, 20.6, 20.3, 20.2, 19.9, 19.7, 19.6,
				19.9, 20.3, 20.6, 20.9, 21.2, 21.6, 21.9, 22.1, 21.7, 21.5 });
		values.add(new double[] { 1.9, 1.2, 0.9, 0.5, 0.1, -0.5, -0.6, MathHelper.NULL_VALUE, MathHelper.NULL_VALUE,
				-1.8, -0.3, 1.4, 3.4, 4.9, 7.0, 6.4, 3.4, 2.0, 1.5, 0.9, -0.5, MathHelper.NULL_VALUE, -1.9, -2.5, -4.3 });

		XYMultipleSeriesDataset dataset = buildDateDataset(titles, x, values);
		return dataset;
	}

	protected XYMultipleSeriesDataset buildDateDataset(String[] titles, List xValues, List yValues) {
		XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
		int length = titles.length;
		for (int i = 0; i < length; i++) {
			TimeSeries series = new TimeSeries(titles[i]);
			Date[] xV = xValues.get(i);
			double[] yV = yValues.get(i);
			int seriesLength = xV.length;
			for (int k = 0; k < seriesLength; k++) {
				series.add(xV[k], yV[k]);
			}
			dataset.addSeries(series);
		}
		return dataset;
	}

	private XYMultipleSeriesRenderer buildRenderer() {

		int[] colors = new int[] { Color.GREEN, Color.BLUE };
		PointStyle[] styles = new PointStyle[] { PointStyle.CIRCLE, PointStyle.DIAMOND };
		XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
		int length = renderer.getSeriesRendererCount();
		for (int i = 0; i < length; i++) {
			((XYSeriesRenderer) renderer.getSeriesRendererAt(i)).setFillPoints(true);
		}

		setChartSettings(renderer, "Sensor temperature", "Hour", "Celsius degrees", x.get(0)[0].getTime(),
				x.get(0)[HOURS - 1].getTime(), -5, 30, Color.LTGRAY, Color.LTGRAY);

		renderer.setXLabels(10);
		renderer.setYLabels(10);
		renderer.setShowGrid(true);
		renderer.setXLabelsAlign(Align.CENTER);
		renderer.setYLabelsAlign(Align.RIGHT);
		return renderer;
	}

	protected XYMultipleSeriesRenderer buildRenderer(int[] colors, PointStyle[] styles) {
		XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
		renderer.setAxisTitleTextSize(16);
		renderer.setChartTitleTextSize(20);
		renderer.setLabelsTextSize(15);
		renderer.setLegendTextSize(15);
		renderer.setPointSize(5f);
		renderer.setMargins(new int[] { 20, 30, 15, 0 });
		int length = colors.length;
		for (int i = 0; i < length; i++) {
			XYSeriesRenderer r = new XYSeriesRenderer();
			r.setColor(colors[i]);
			r.setPointStyle(styles[i]);
			renderer.addSeriesRenderer(r);
		}
		return renderer;
	}

	protected void setChartSettings(XYMultipleSeriesRenderer renderer, String title, String xTitle, String yTitle,
			double xMin, double xMax, double yMin, double yMax, int axesColor, int labelsColor) {
		renderer.setChartTitle(title);
		renderer.setXTitle(xTitle);
		renderer.setYTitle(yTitle);
		renderer.setXAxisMin(xMin);
		renderer.setXAxisMax(xMax);
		renderer.setYAxisMin(yMin);
		renderer.setYAxisMax(yMax);
		renderer.setAxesColor(axesColor);
		renderer.setLabelsColor(labelsColor);
	}
}

3. AndroidManifest.xml 에 다음 Activity 정의 추가

	
	
	
	

'Android' 카테고리의 다른 글

[안드로이드]Smart Switch release  (0) 2014.06.09
[안드로이드]Wifi Scanning 에 대한 방법  (0) 2014.06.03
Embedded AChartEngine  (2) 2011.04.11
Pick up the phone  (1) 2011.04.08
Android Custom ListView with CheckBox  (7) 2011.03.03
WiFi Monitor  (0) 2011.02.16




Posted by 금붕어70
Android2011.04.08 14:10





"Pick up the phone.(전화 받으세요)" 만들어서 출시 하였습니다.
아내는 교회를  다녀오거나 도서관에 갈때는 항상 휴대폰을 진동으로 변경하고는 원래 상태로 되돌리는 것을 잊어 버립니다.
급하게 연락해야 할때는 그것때문에 많이 싸우기도하였습니다.
나이가 들어가면서 반복적으로 해야할 일도 점점 더 잊어버리는 경향이 있습니다. 물론 저도 마찬가지지만....

부재중 전화가 지정된 시간 몇 번이상 오면 벨소리 볼륨과 진동을 옵션에서 설정한데로 복구하는 기능을 개발하였습니다.
조금은 복잡해 보이는데 그래도 한번 설정하면 잊어 먹고 편하게 살수 있어서 좋을 것 같습니다.
문자 메세지로도 핸드폰을 조정할 수 있습니다.
벨소리, 진동, 무선인터넷 켜기/끄기 와 휴대폰이 탑재된 센스 정보를 이용하여 필요하면 받아 올수 있습니다.
이 정보로 휴대폰을 가진 사람이 이동중인지 휴대폰과 떨어져 있는지를 대충 알 수 있습니다.
* Free 버젼과 Donate 버젼 2가지가 있습니다.  
https://market.android.com/details?id=com.nalsil.DroidControl&feature=search_result






'Android' 카테고리의 다른 글

[안드로이드]Wifi Scanning 에 대한 방법  (0) 2014.06.03
Embedded AChartEngine  (2) 2011.04.11
Pick up the phone  (1) 2011.04.08
Android Custom ListView with CheckBox  (7) 2011.03.03
WiFi Monitor  (0) 2011.02.16
Android ImageView ZoomIn/ZoomOut, Move  (0) 2010.05.11




Posted by 금붕어70
Android2011.03.03 17:32




 


안드로이드용 앱을 개발하면서 많은 샘플을 찾아보고 그것을 적용하여 새로운 무엇인가를 만드는 과정중에 찾기가
너무나 힘든것이 하나 있는데, 그것은 CheckBox를 가지고 있는 ListView 를 구현하는 방법이다.

처음에는 별에별 편법을 다 동원해서 해보았는데 아무리 봐도 정석은 아닌듯....
그래서 초심으로 돌아간 마음으로 새롭게 접근해보았습니다.

일단은 Android Playing With ListView Choice Mode[출처] 안드로이드사이드 - http://www.androidside.com/B46/11861  로 부터의 샘플을 가지고 구현해보았습니다.

LVSample1 은 RadioButton 을 사용한 ArrayAdapter 로 구현한  ListView 샘플입니다.


LVSample2 는 CheckBox를 사용한  ArrayAdapter 로 구현한 ListView 샘플입니다.

마지막 LVSample3은 BaseAdapter 를 상속한 Custom Adapter와 Checkable Interface를 이용한 ListView 구현 샘플입니다.
마지막 LVSample3은 버튼 컨트롤을 사용한 ListView 데이터에 접근하여 조회/추가/삭제를 하는 기능을 보여줍니다.

간단한 LVSample3의 중요 소스는  다음과 같습니다.


* LVSample3.java
public class LVSample3 extends Activity implements OnClickListener {

	private Button btnSearch;
	private Button btnAdd;
	private Button btnDelete;

	private ListView lv;
	private List dataSources;
	private ListAdapter adapter;

	private DialogInterface.OnClickListener deleteYesListener;
	private DialogInterface.OnClickListener deleteNoListener;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.main);

		// For Buttons
		btnSearch = (Button) findViewById(R.id.btnSearch);
		btnSearch.setOnClickListener(this);

		btnAdd = (Button) findViewById(R.id.btnAdd);
		btnAdd.setOnClickListener(this);

		btnDelete = (Button) findViewById(R.id.btnDelete);
		btnDelete.setOnClickListener(this);

		// For Custom ListView
		dataSources = getDataSource();
		adapter = new LVSample3Adapter(dataSources, this);
		this.lv = (ListView) findViewById(R.id.listview);
		this.lv.setAdapter(adapter);
		this.lv.setItemsCanFocus(false);
		this.lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
		// lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

		this.lv.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView adapt, View view, int position, long id) {
				// TODO Auto-generated method stub
				TextView tvTitle = (TextView) view.findViewById(R.id.title);
				TextView tvSummary = (TextView) view.findViewById(R.id.summary);
				String message = "Title: " + tvTitle.getText() + "\n" + "Summary:" + tvSummary.getText();
				ShowMessageBox(LVSample3.this, message);
			}
		});

	}

	@Override
	public void onClick(View view) {
		if (view.getId() == R.id.btnSearch) {
			// long[] checkedItems = this.lv.getCheckItemIds();
			Long[] checkedItems = ((LVSample3Adapter) adapter).getCheckItemIds();
			if (checkedItems == null || checkedItems.length == 0) {
				ShowMessageBox(this, "Selected Items is Nothing.");
				return;
			}

			String message = "";
			for (int index = 0; index < checkedItems.length; index++) {
				long pos = checkedItems[index];
				LVSample3Item item = dataSources.get((int) pos);
				message += String.format("%d[%s, %s]\n", pos, item.getTitle(), item.getSummary());
			}
			ShowMessageBox(this, message);

		} else if (view.getId() == R.id.btnAdd) {
			addDataSource(this.dataSources);
			((LVSample3Adapter) adapter).notifyDataSetChanged();
			ShowMessageBox(this, String.format("All items count is %d.", dataSources.size()));
		} else if (view.getId() == R.id.btnDelete) {
			// long[] checkedItems = this.lv.getCheckItemIds();
			Long[] checkedItems = ((LVSample3Adapter) adapter).getCheckItemIds();
			if (checkedItems == null || checkedItems.length == 0) {
				ShowMessageBox(this, "Selected items is Nothing.");
				return;
			}

			// Dialog Setting
			deleteYesListener = new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int id) {
					// long[] checkedItems = lv.getCheckItemIds();
					Long[] checkedItems = ((LVSample3Adapter) adapter).getCheckItemIds();

					for (int index = checkedItems.length - 1; index >= 0; index--) {
						long pos = checkedItems[index];
						dataSources.remove((int) pos);
					}
					// lv.clearChoices();
					((LVSample3Adapter) adapter).clearChoices();
					((LVSample3Adapter) adapter).notifyDataSetChanged();
					ShowMessageBox(LVSample3.this, String.format("All items count is %d.", dataSources.size()));
				}
			};

			deleteNoListener = new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int id) {
					dialog.cancel();
				}
			};

			ShowMessageYesNo(this, "Delete", "Are you sure you want to delete selected item(s)?", deleteYesListener,
					deleteNoListener);
		}
	}

	private static List getDataSource() {
		List lstItems = new ArrayList();

		for (int i = 0; i < 20; i++) {
			LVSample3Item item = new LVSample3Item("Action" + i, "This is a test mssage.");
			lstItems.add(item);
		}
		return lstItems;
	}

	private static List addDataSource(List dataSources) {
		LVSample3Item item = new LVSample3Item("Added" + dataSources.size(), "This is a added mssage.");
		dataSources.add(item);

		return dataSources;
	}

	private static void ShowMessageBox(Context context, String message) {
		Toast.makeText(context, message, Toast.LENGTH_LONG).show();
	}

	public static void ShowMessageYesNo(Context context, String title, String message,
			DialogInterface.OnClickListener YesListener, DialogInterface.OnClickListener NoListener) {
		AlertDialog.Builder alterBuilder = new AlertDialog.Builder(context);
		alterBuilder.setMessage(message).setCancelable(false).setPositiveButton(android.R.string.yes, YesListener)
				.setNegativeButton(android.R.string.no, NoListener);
		AlertDialog alert = alterBuilder.create();
		// Title for AlertDialog
		alert.setTitle(title);
		// Icon for AlertDialog
		alert.setIcon(R.drawable.icon);
		alert.show();
	}
}


* LVSample3Adapter.java
public class LVSample3Adapter extends BaseAdapter {

	private List itemList;
	private Context context;
	public Hashtable hashConvertView = new Hashtable();

	public LVSample3Adapter(List itemList, Context context) {
		this.itemList = itemList;
		this.context = context;
	}

	public int getCount() {
		return itemList.size();
	}

	public LVSample3Item getItem(int position) {
		return itemList.get(position);
	}

	public long getItemId(int position) {
		return itemList.get(position).getId();
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		LVSample3Item item = itemList.get(position);

		ViewHolder holder;
		if (hashConvertView.containsKey(position) == false) {
			convertView = (com.nalsil.ListViewSample.CheckableRelativeLayout) LayoutInflater.from(context).inflate(
					R.layout.my_list_item3, parent, false);
			holder = new ViewHolder();

			holder.tvTitle = (TextView) convertView.findViewById(R.id.title);
			holder.tvSummary = (TextView) convertView.findViewById(R.id.summary);
			holder.chk = (CheckBox) convertView.findViewById(R.id.check);
			holder.chk.setId(position);
			holder.chk.setOnClickListener(listener);

			convertView.setTag(holder);
			hashConvertView.put(position, convertView);
		} else {
			convertView = (View) hashConvertView.get(position);
			holder = (ViewHolder) convertView.getTag();
		}
		holder.tvTitle.setText(item.getTitle());
		holder.tvSummary.setText(item.getSummary());

		return convertView;
	}

	private final OnClickListener listener = new OnClickListener() {
		public void onClick(View v) {
			if (v instanceof CheckBox) {
				CheckBox chk = (CheckBox) v;

				// switch (chk.getId()) {
				// }
				notifyDataSetChanged();
				// notifyDataSetInvalidated();
			}
		}
	};

	public Long[] getCheckItemIds() {
		if (hashConvertView == null || hashConvertView.size() == 0)
			return null;

		Integer key;
		View view;
		List lstIds = new ArrayList();
		Enumeration e = hashConvertView.keys();
		long index = 0;
		while (e.hasMoreElements()) {
			key = (Integer) e.nextElement();
			view = (View) hashConvertView.get(key);
			ViewHolder holder = (ViewHolder) view.getTag();
			if (holder.chk.isChecked()) {
				lstIds.add(index);
			}
			index++;
		}

		Long[] arrLong = (Long[]) lstIds.toArray(new Long[0]);
		return arrLong;
	}

	public void clearChoices() {
		if (hashConvertView == null || hashConvertView.size() == 0)
			return;

		Integer key;
		View view;
		List lstIds = new ArrayList();
		Enumeration e = hashConvertView.keys();
		long index = 0;
		while (e.hasMoreElements()) {
			key = (Integer) e.nextElement();
			view = (View) hashConvertView.get(key);
			ViewHolder holder = (ViewHolder) view.getTag();
			if (holder.chk.isChecked()) {
				holder.chk.setChecked(false);
			}
			index++;
		}
	}

	static class ViewHolder {
		CheckBox chk;
		TextView tvTitle;
		TextView tvSummary;
	}
}

* LVSample3Item.java
public class LVSample3Item implements Serializable {

	private static final long serialVersionUID = -1586987653093943671L;
	private static long index = 0;
	private long Id = 0;
	private String title;
	private String summary;

	public LVSample3Item(String title, String summary) {
		Id = index++;
		this.title = title;
		this.summary = summary;
	}

	public long getId() {
		return Id;
	}

	public void setId(long Id) {
		this.Id = Id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}
}

* main.xml



	

		

		

		
	

	




* my_list_item3.xml



	

	

	

	


'Android' 카테고리의 다른 글

[안드로이드]Wifi Scanning 에 대한 방법  (0) 2014.06.03
Embedded AChartEngine  (2) 2011.04.11
Pick up the phone  (1) 2011.04.08
Android Custom ListView with CheckBox  (7) 2011.03.03
WiFi Monitor  (0) 2011.02.16
Android ImageView ZoomIn/ZoomOut, Move  (0) 2010.05.11




Posted by 금붕어70
TAG ListView
Android2011.02.16 17:50




안드로이드 OS 개발 환경을 공부하기 위해 이번에 WiFi Monitor 라는 앱을 출시했다.
가끔씩 죽고 오동작도 하지만 안드로이드를 공부하면서 익혔든 모든 내용을 총 망라했다
시간이 지나면 조금더 조금 더 나아 지리라 기대한다.

URL:   market://details?id=com.nalsil.WiFiMonitor

'Android' 카테고리의 다른 글

[안드로이드]Wifi Scanning 에 대한 방법  (0) 2014.06.03
Embedded AChartEngine  (2) 2011.04.11
Pick up the phone  (1) 2011.04.08
Android Custom ListView with CheckBox  (7) 2011.03.03
WiFi Monitor  (0) 2011.02.16
Android ImageView ZoomIn/ZoomOut, Move  (0) 2010.05.11




Posted by 금붕어70
Android2010.05.11 17:33





안드로이드 이미지를 제어하기 위해서 기본적인 이미지 확대,축소, 이동을 위한 샘플이 있습니다.
matrix를 사용한 변환을 활용하는 예제입니다.

"Hello, Android" 의 첨부 소스 코드를 참고하시면 도움이 되실듯...
http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2-part-4-setting-up-for-image-transformation/1785

첨부 소스 코드는 이곳에 있습니다.
http://www.pragprog.com/titles/eband3/source_code


'Android' 카테고리의 다른 글

[안드로이드]Wifi Scanning 에 대한 방법  (0) 2014.06.03
Embedded AChartEngine  (2) 2011.04.11
Pick up the phone  (1) 2011.04.08
Android Custom ListView with CheckBox  (7) 2011.03.03
WiFi Monitor  (0) 2011.02.16
Android ImageView ZoomIn/ZoomOut, Move  (0) 2010.05.11




Posted by 금붕어70
TAG Android, ZOOM