当前位置: 编程技术>移动开发
本页文章导读:
▪两个座标间画线 两个坐标间画线
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
linearLayout = (LinearLayout) fi.........
▪ andriod学习札记 andriod学习笔记
根据标准tutorial,学习了android的view,里面讲layout和view合并的概念还是有点不清楚。
想起了当年学swing时的layoutManager,特别是哪个relativeLayoutManager着实让我云里雾里的,现在还.........
▪ 获得手机下绑定的Google账号 获得手机上绑定的Google账号
1.5和1.6的系统里没有现成的方法,因而需要用到第三方的库
/**
* use 3rd package to get Google Account
*
* @param activity
* @param requestCode
*/
private void getGoogleService(Activit.........
[1]两个座标间画线
来源: 互联网 发布时间: 2014-02-18
两个坐标间画线
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); linearLayout = (LinearLayout) findViewById(R.id.zoomview); mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); mapOverlays = mapView.getOverlays(); projection = mapView.getProjection(); mapOverlays.add(new MyOverlay()); } @Override protected boolean isRouteDisplayed() { return false; } class MyOverlay extends Overlay{ public MyOverlay(){ } public void draw(Canvas canvas, MapView mapv, boolean shadow){ super.draw(canvas, mapv, shadow); mPaint = new Paint(); mPaint.setDither(true); mPaint.setColor(Color.RED); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(2); GeoPoint gP1 = new GeoPoint(19240000,-99120000); GeoPoint gP2 = new GeoPoint(37423157, -122085008); Point p1 = new Point(); Point p2 = new Point(); path = new Path(); projection.toPixels(gP1, p1); projection.toPixels(gP2, p2); path.moveTo(p2.x, p2.y); path.lineTo(p1.x,p1.y); canvas.drawPath(path, mPaint); }
[2] andriod学习札记
来源: 互联网 发布时间: 2014-02-18
andriod学习笔记
根据标准tutorial,学习了android的view,里面讲layout和view合并的概念还是有点不清楚。
想起了当年学swing时的layoutManager,特别是哪个relativeLayoutManager着实让我云里雾里的,现在还不是很清楚,看看android怎么处理这个问题。有兴趣的同学留个言,还有stay tuned...
[3] 获得手机下绑定的Google账号
来源: 互联网 发布时间: 2014-02-18
获得手机上绑定的Google账号
1.5和1.6的系统里没有现成的方法,因而需要用到第三方的库
返回值需要用下面的方法获得
这个方法需要在AndroidManifest.xml里增加
<uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH" />
2.0以后的版本,可以通过AccountManager来获得
考虑到程序可能在低版本的机器上运行,所以方法调用都使用了反射
附件为自己写的代码(包含第三方库文件),写得不好,请多包涵
1.5和1.6的系统里没有现成的方法,因而需要用到第三方的库
/** * use 3rd package to get Google Account * * @param activity * @param requestCode */ private void getGoogleService(Activity activity, int requestCode) { try { for (Method ele : Class.forName( "com.google.android.googlelogin.GoogleLoginServiceHelper") .getMethods()) { try { if (ele.getName().equals("getAccount")) { ele.invoke(null, activity, requestCode, true); } } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } catch (ClassNotFoundException e) { e.printStackTrace(); } }
返回值需要用下面的方法获得
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_GOOGLE_ACCOUNT) { String key = "accounts"; String accounts[] = data.getExtras().getStringArray(key); if (accounts != null && accounts[0] != null) { String account = accounts[0]; } } }
这个方法需要在AndroidManifest.xml里增加
<uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH" />
2.0以后的版本,可以通过AccountManager来获得
/** * use Account Manager to get Google Account * * @param activity */ private void getGoogleServiceWithAccountManager(Activity activity) { try { // declare class AccountManager Class MyAccountManager = Class.forName("android.accounts.AccountManager"); // declare method getAccounts of AccountManager Method mGetAccounts = MyAccountManager.getDeclaredMethod("getAccounts"); for (Method ele : MyAccountManager.getMethods()) { try { if (ele.getName().equals("get")) { // call AccountManager.get to create an instance Object obj = ele.invoke(null, activity); // call AccountManager.getAccount to get Account[] Object accounts[] = (Object[]) mGetAccounts.invoke(obj, null); if (accounts.length > 0) { // get the class member "name" of class Account Field f = accounts[0].getClass().getDeclaredField("name"); // get the value of class member "name" this.mAccount = (String) f.get(accounts[0]); } } } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } } } catch (SecurityException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } finally { returnGoogleAccount(); } }
考虑到程序可能在低版本的机器上运行,所以方法调用都使用了反射
附件为自己写的代码(包含第三方库文件),写得不好,请多包涵
最新技术文章: