Saturday, November 8, 2014

在Eclipse配置UML

name: UML (objectAid) to write class & sequence diagram
序列图需要注册账号,可以免费用一个月
link: http://www.objectaid.com/

其他use case, architecture diagram可以用visio 来画

Tuesday, October 28, 2014

Android: UI design

Fragment in Activity(xml in xml)
方法一(不推荐): 类似于MyStatsFragment,MyStatsFragment初始化xml2,然后取代要内置的占位的那一行xml1

方法二:<include>重用xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="fill_parent" android:layout_height="fill_parent"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <FrameLayout android:id="@+id/content_frame" android:layout_width="fill_parent" android:layout_height="fill_parent" />
    <include
        android:id="@+id/left_drawer"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        layout="@layout/fragment_left_menu"
        />
</android.support.v4.widget.DrawerLayout>

fragment_left_menu为xml2的名字
http://developer.android.com/training/improving-layouts/reusing-layouts.html
ListView
ArrayAdatper and simpleAdapter
http://www.vogella.com/tutorials/AndroidListView/article.html

custom click:
 adapter = new SimpleAdapter(getActivity(), list,
   R.layout.pageview_timeline_cardview, from, to)
{
   @Override
   public View getView(int position, View convertView,
           ViewGroup parent) {
       View view =super.getView(position, convertView, parent);
       final int pos = position;
       RelativeLayout rlayout=(RelativeLayout) view.findViewById(R.id.rgm_card);
       rlayout.setOnClickListener(new OnClickListener()
        {

           @Override
           public void onClick(View v)
           {
            Log.d(TAG, pos);
           }
       });

       return view;
   }
};

Action bar

@Override
public boolean onOptionsItemSelected(MenuItem item) 
{    
   switch (item.getItemId()) 
   {        
      case android.R.id.home:            
         Intent intent = new Intent(this, ActOnThisActivity.class);            
         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
         startActivity(intent);            
         return true;        
      default:            
         return super.onOptionsItemSelected(item);    
   }
}
ActionBar bar = getActionBar();
bar.setDisplayHomeAsUpEnabled(true);
http://www.informit.com/articles/article.aspx?p=1743642&seqNum=4

Action bar with right hand side:
可能需要android-support-v7-appcompat.jar
<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
    <item android:id="@+id/action_search"
          android:icon="@drawable/map_icon_default"
          android:title="Checkin"
          android:showAsAction="ifRoom" />
</menu>

//action bar right hand side
@Override
public boolean onCreateOptionsMenu(Menu menu) {
   // Inflate the menu items for use in the action bar
   MenuInflater inflater = getMenuInflater();
   inflater.inflate(R.menu.pathlist_activity_actions, menu);
   return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
        case R.id.action_search:
            openSearch();
            return true;
        case R.id.action_compose:
            composeMessage();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}


Navigation Drawer

http://blog.csdn.net/xyz_lmn/article/details/12523895
https://developer.android.com/design/patterns/navigation-drawer.html
https://www.codeofaninja.com/2014/02/android-navigation-drawer-example.html



Custom theme:

Custom theme

http://stackoverflow.com/questions/11675500/sherlock-actionbar-styles


Dialog:

     RecordDialogFragment dialog = new RecordDialogFragment();
    dialog.show(getFragmentManager(), "NoticeDialogFragment");

DialogFragment

Monday, October 27, 2014

Android: Http post文件到php server



http://androidcodeforbeginners.blogspot.in/2013/05/send-xml-data-from-android-to-php-server.html

Sunday, October 26, 2014

Android: dynamic list view


这个layout.xml是固定的具体可以看一下贴
http://blog.csdn.net/flowingflying/article/details/6256739

Friday, October 24, 2014

Android: 组件间通信(activity, fragment, service)


service和activity通信

Activity:
 Intent serviceIntent = new Intent(this,ListenLocationService.class);
   serviceIntent.putExtra("From", "Main");
   startService(serviceIntent);
//and get the parameter in onStart method of your service class

service:
@Override
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);
     Bundle extras = intent.getExtras();
if(extras == null)
    Log.d("Service","null");
else
{
    Log.d("Service","not null");
    String from = (String) extras.get("From");
    if(from.equalsIgnoreCase("Main"))
        StartListenLocation();
}

如果putExtra输入是Int, 在bundle就要用getInt 类型一定要match 否则报错!


Fragment和Activity通信:

Fragment->Activity:
In your fragment you can call getActivity(). This will give you access to the activity that created the fragment. From there you can obviously call any sort of accessor methods that are in the activity.

MainFragmentActivity parent;
parent.setCurrentLatLng(new LatLng(location.getLatitude(),location.getLongitude()));

setCurrentLatLng是activity的方法



Activity和Activity通信:

基本类型:
    Activity 1:
                Intent intent = new Intent(getActivity() ,PathDetailActivity.class);
                int pathid=pos;
                intent.putExtra("pathid", pathid);
                getActivity().startActivity(intent);
    Activity 2
            Intent intent = getIntent();
   int pathid = intent.getIntExtra("pathid", 0);

复合类型:

    Activity 1:
             Intent intent = new Intent(getActivity() ,PathDetailActivity.class);
                      Bundle data = new Bundle(); data.putParcelable("stats", stats.get(pos));                    
                      intent.putExtra("bundle",data); getActivity().
                      startActivity(intent);
    Activity 2
             Intent intent = getIntent();
   Bundle bundle = intent.getParcelableExtra("bundle");
    Stats stats = bundle.getParcelable("stats");

这里Stats必须是实现Parcelable
http://techdroid.kbeanie.com/2010/06/parcelable-how-to-do-that-in-android.html

    Activity 1:
      Bundle data = new Bundle();
    Intent intent = new Intent(MainFragmentActivity.this,CheckinActivity.class);
    //intent.putExtra("pathid", pathid);
    data.putParcelable("currentPoint", this.curPoint);
    data.putInt("pathid", pathid);
    intent.putExtra("bundle",data);
    startActivity(intent);

利用intent通信,数据可以是基本类型(pathid is int),也可以是复合甚至自定义类型,可以用bundle封装 curPoint是LatLng类型.

Activity 2(onCreate):
            Intent intent = getIntent();
   //pathid = intent.getIntExtra("pathid", 0);
   Bundle bundle = intent.getParcelableExtra("bundle");
   curPoint = bundle.getParcelable("currentPoint");
   pathid = bundle.getInt("pathid");

当然也可以用data.putSerializable("person",p)来封装,具体见android讲义P240

Wednesday, October 8, 2014

Eclipse安装C++


下载CDT更新
http://download.eclipse.org/tools/cdt/releases/juno
ref:
http://jingyan.baidu.com/article/380abd0a5888211d90192cd6.html

此时Eclipse内部可以build C++了,但是好似不能运行

安装MinGW,把bin目录加入环境变量path,make**.ext那个改成make.exe,打开cmd测试make,这时可以进入eclipse生成的CTest.exe运行,即可出现想要的结果

或者C++ online: http://cpp.sh/
python online: http://repl.it/languages/Python

Saturday, October 4, 2014

Android之ConentProvider Uri详解

假设我们的contentProvider名叫PathRecordingService, 这里在AndroidManifest.xml中可以看到
          <provider
        android:name="edu.njit.trackmypath.db.DataProvider"
        android:authorities="edu.njit.trackmypath"
        android:exported="true"/>

在DAO类,定义Uri CONTENT_URI: content://edu.njit.trackmypath/pathpoints, 这是要监听的Uri对应是table pathpoints,当然Uri和table也可以不一致。还有定义
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.njit.pathpoint";
public static final String CONTENT_ITEMTYPE = "vnd.android.cursor.item/vnd.njit.pathpoint";


在ContentProvider中,定义Uri
   public static final String AUTHORITY = "edu.njit.trackmypath";
    private static final int PATHPOINTS_TABLE_ID = 1;

    private static final UriMatcher uriMatcher;
    static {
            uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
            uriMatcher.addURI(AUTHORITY, PathPointsTable.TABLE_NAME,                    
                             PATHPOINTS_TABLE_ID);
    }

public String getType(Uri uri) {

switch (uriMatcher.match(uri))
{
       case PATHPOINTS_TABLE_ID:
        return PathPointsTable.CONTENT_TYPE;
       default:
           throw new IllegalArgumentException("Error Uri: " + uri);
              }
}
这里PATHPOINTS_TABLE_ID只是一个Uri的整数代号,所以在这里CONTENT_URI就返回PathPointsTable.CONTENT_TYPE对应DAO中是vnd.android.cursor.dir。vnd.android.cursor.dir和vnd.android.cursor.item是Android中两种Uri解释方式,dir是全表变化监听,而item是监听某Row的变化。如果要监听某row,如下:
uriMatcher.addURI(AUTHORITY, “pathpoints/#”,2)
返回应选CONTENT_ITEMTYPE, #代表数字
这样就可以监听某行变化,如content://edu.njit.trackmypath/pathpoints/28

而监听变化的实现是在ContentProvider中
@Override
public Uri insert(Uri uri, ContentValues values) {
long id = db.insert(PathPointsTable.TABLE_NAME, PathPointsTable._ID, values);
if(id < 0)
throw new SQLiteException("Unable to insert " + values + " for " + uri);

Uri newUri = ContentUris.withAppendedId(uri, id);
Log.d(TAG, "new URI:"+newUri);
                resolver.notifyChange(newUri, null);  

                return newUri;
}
newUri是content://edu.njit.trackmypath/pathpoints/28,notifyChange就会通知observer
context.getContentResolver().registerContentObserver(uri, true, observer);

Ref:
http://blog.csdn.net/luoshengyang/article/details/6950440
http://blog.csdn.net/luoshengyang/article/details/6985171