PACKAGE: com.example.android.apis.app
CustomDialogActivity.java
SEE:
1.custom_dialog_activity.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text"
android:layout_width="match_parent" android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal"
android:text="@string/custom_dialog_activity_text"/>
2.AndroidManifest.xml
<activity android:name=".app.CustomDialogActivity"
android:label="@string/activity_custom_dialog"
android:theme="@style/Theme.CustomDialog">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.SAMPLE_CODE" />
</intent-filter>
</activity>
3.values.styles.xml
<style name="Theme.CustomDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@drawable/filled_box</item>
</style>
4.drawable.fill_box.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#f0600000"/>
<stroke android:width="3dp" color="#ffff8080"/>
<corners android:radius="3dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
SO:很是纠结的一个设置呀,解耦解成这样不容易呀。

CustomTitle.java

SEE:
1.onCreate()
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);
2.layout.custom_title_1.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/screen"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical">
<TextView android:id="@+id/left_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="@string/custom_title_left" />
<TextView android:id="@+id/right_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="@string/custom_title_right" />
</RelativeLayout>

SO:
设置标题栏样式的方法。。。

DialogActivity.java
SEE:
1.onCreate() =>
requestWindowFeature(Window.FEATURE_LEFT_ICON);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
android.R.drawable.ic_dialog_alert);
SO:
设置那个感叹号的方法。。。 真短。。其他应该同CUSTOM_DIALOG


Forwarding.java
SEE:
1.onClick() =>
Intent intent = new Intent();
intent.setClass(Forwarding.this, ForwardTarget.class);
startActivity(intent);
finish();
SO:
只要finish()掉这个activity,就不会呆在栈上了。。回来也见不到他了。。


HelloWorld.java

无视。。
SEE:
1.res.value.string.xml
<string name="hello_world"><b>Hello, <i>World!</i></b></string>
SO:
这里可以设置格式。。。


PersistentState.java

SEE:
1.save_restore_state.xml
<EditText android:id="@+id/saved"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/green"
android:text="@string/initial_text"
android:freezesText="true">
<requestFocus />
</EditText>
2.onResume()
SharedPreferences prefs = getPreferences(0);
String restoredText = prefs.getString("text", null);
if (restoredText != null) {
mSaved.setText(restoredText, TextView.BufferType.EDITABLE);

int selectionStart = prefs.getInt("selection-start", -1);
int selectionEnd = prefs.getInt("selection-end", -1);
if (selectionStart != -1 && selectionEnd != -1) {
mSaved.setSelection(selectionStart, selectionEnd);
}
}
3.onPause()
SharedPreferences.Editor editor = getPreferences(0).edit();
editor.putString("text", mSaved.getText().toString());
editor.putInt("selection-start", mSaved.getSelectionStart());
editor.putInt("selection-end", mSaved.getSelectionEnd());
editor.commit();
SO:
见sharePreferences的保存方式~。。。 这个还可以保存选择文字 的开始点和结束点
=========================END


QuickContactsDemo.JAVA
SEE:
1.QuickContactsDemo.java
static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] {
Contacts._ID, // 0
Contacts.DISPLAY_NAME, // 1
Contacts.STARRED, // 2
Contacts.TIMES_CONTACTED, // 3
Contacts.CONTACT_PRESENCE, // 4
Contacts.PHOTO_ID, // 5
Contacts.LOOKUP_KEY, // 6
Contacts.HAS_PHONE_NUMBER, // 7
};
2.onCreate()
String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND ("
+ Contacts.HAS_PHONE_NUMBER + "=1) AND ("
+ Contacts.DISPLAY_NAME + " != '' ))";
Cursor c =
getContentResolver().query(Contacts.CONTENT_URI, CONTACTS_SUMMARY_PROJECTION, select,
null, Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
SO:
获得了联系人的表,需要什么参数什么条件再改。。。


SEE:
1.startManagingCursor(c);
SO:
startManagingCursor(Cursor c)
This method allows the activity to take care of managing the given Cursor's lifecycle for you based on the activity's lifecycle.

SEE:
1.
final ContactListItemCache cache = (ContactListItemCache) view.getTag();
2.
final static class ContactListItemCache {
public TextView nameView;
public QuickContactBadge photoView;
public CharArrayBuffer nameBuffer = new CharArrayBuffer(128);
}
3.
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = super.newView(context, cursor, parent);
ContactListItemCache cache = new ContactListItemCache();
cache.nameView = (TextView) view.findViewById(R.id.name);
cache.photoView = (QuickContactBadge) view.findViewById(R.id.badge);
view.setTag(cache);

return view;
}
SO:
getTag () returns the Object stored in this view as a tag将某个对象作为tag保存在view中。。 在newView中进行tag和View的绑定。隐藏view的细节。。。设置的时候不用一直findViewById了

SEE:
1.bindView()
SO:
abstract void bindView () Bind an existing view to the data pointed to by cursor


SEE:
1.bindView()
final ContactListItemCache cache = (ContactListItemCache) view.getTag();
TextView nameView = cache.nameView;
QuickContactBadge photoView = cache.photoView;
// Set the name
cursor.copyStringToBuffer(SUMMARY_NAME_COLUMN_INDEX, cache.nameBuffer);
int size = cache.nameBuffer.sizeCopied;
cache.nameView.setText(cache.nameBuffer.data, 0, size);
final long contactId = cursor.getLong(SUMMARY_ID_COLUMN_INDEX);
final String lookupKey = cursor.getString(SUMMARY_LOOKUP_KEY);
cache.photoView.assignContactUri(Contacts.getLookupUri(contactId, lookupKey));
SO:
cursor的取值操作,绑定View的tag的设置工作。。

SEE:
1.
ContactListItemAdapter adapter = new ContactListItemAdapter(this, R.layout.quick_contacts, c);
2.
layout.quick_contacts.xml
SO:看看就好 adapter的每一项的布局。。

ReseiveResult.java
SEE:
1.onClick()
Intent intent = new Intent(ReceiveResult.this, SendResult.class);
startActivityForResult(intent, GET_CODE);
2.
protected void onActivityResult(int requestCode, int resultCode,
Intent data)
SO:
开始一个Activity来接收result

SEE: SendResult.java
1.
setResult(RESULT_OK, (new Intent()).setAction("Corky!"));
finish();
SO:
返回 ok 并带回一个结果。。。。 居然以ACTION的形式传回来。。 而不是intent.putExtra,懒呀 懒呀。


RedirectMain.java
SEE:
1.RedirectEnter.java
Intent intent = new Intent(RedirectEnter.this, RedirectMain.class);
startActivity(intent);
2.RedirectMain.java
if (!loadPrefs()) {
Intent intent = new Intent(this, RedirectGetter.class);
startActivityForResult(intent, INIT_TEXT_REQUEST);
}
...
if (resultCode == RESULT_CANCELED) {
finish();
SO:
进来无数据就跳走,返回为CANCELLED就finish();这个逻辑真纠结。

SEE:
1.RedirectGetter.java
SharedPreferences preferences = getSharedPreferences("RedirectData", 0);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("text", mText.getText().toString());

if (editor.commit()) {
setResult(RESULT_OK);
}
SO:
在复习一次sharedPreferences保存方法。


ReorderOnLaunch.java

SEE:
1.ReorderFour.java
Intent intent = new Intent(ReorderFour.this, ReorderTwo.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
SO:
如果栈中有这个Activity则放到最前端。点了N多下之后,如果返回的话,会发现second只有一个。。。因为总是被带到前端来,而不是重新创建一个实例。。 singletask ?


SaveRestoreState.java
1.
/**
* Retrieve the text that is currently in the "saved" editor.
*/
CharSequence getSavedText() {
return ((EditText)findViewById(R.id.saved)).getText();
}

/**
* Change the text that is currently in the "saved" editor.
*/
void setSavedText(CharSequence text) {
((EditText)findViewById(R.id.saved)).setText(text);
}
2.
<EditText android:id="@+id/saved"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/green"
android:text="@string/initial_text"
android:freezesText="true">
<requestFocus />
</EditText>
SO:
横竖屏的切换实际上是销毁一个ACTIVITY并创建另一个ACTIVITY,当然不能保存EditText里的数据,根据一个属性 android:freezesText="true" 两个方法getSavedText() setSavedText() 就能保存里面的数据。



SetWallpaperActivity.java

SEE:
1.layout.wallpaper.xml
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageview" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent">
SO:
这样布局就有背景与按钮两层了。。。 FrameLayout原来以为很废物的。。

SEE:
1.onCreate()
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
final ImageView imageView = (ImageView) findViewById(R.id.imageview);
imageView.setDrawingCacheEnabled(true);
imageView.setImageDrawable(wallpaperDrawable);
SO:
获取WallpaperManager 然后又获取 Drawable 然后就可以获取壁纸了。

SEE:
1.
int mColor = (int) Math.floor(Math.random() * mColors.length);
wallpaperDrawable.setColorFilter(mColors[mColor], PorterDuff.Mode.MULTIPLY);
imageView.setImageDrawable(wallpaperDrawable);
imageView.invalidate();
SO:
设置一个Drawable的ColorFilter就可以有滤镜的效果。。。待研究

SEE:
1.
wallpaperManager.setBitmap(imageView.getDrawingCache());
2. imageView.setDrawingCacheEnabled(true);
SO:获取View的DrawingCache,输出到WallpaperManager成壁纸。应该也可以输出到别的地方吧,把一个view的DrawingCache来做变换效果。根view的难道可以实现截屏?。。MARK


TranslucentActivity.java

SEE:
1.AndroidManifest.xml
<activity android:name=".app.TranslucentActivity"
android:label="@string/activity_translucent"
android:theme="@style/Theme.Translucent">
2.values.styles.xml
<style name="Theme.Translucent" parent="android:style/Theme.Translucent">
<item name="android:windowBackground">@drawable/translucent_background</item>
<item name="android:windowNoTitle">true</item>
<item name="android:colorForeground">#fff</item>
</style>
SO:
将android:windowBackground设置为@drawable/translucent_background应该就可以了吧

TranslucentBlueActivity.java
SEE:
1.onCreate()
getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
SO:
背景模糊效果~


WallpaperActivity.java

SEE
1.values.style.xml
<style name="Theme.Wallpaper" parent="android:style/Theme.Wallpaper">
<item name="android:colorForeground">#fff</item>
</style>
SO:不是Theme.Translucent而已。。。
==========================终于完了







更多相关文章

  1. android SDK更新方法总结
  2. android 设置透明效果
  3. Android文字的阴影效果
  4. 短视频源码,实现文字横向移动效果(跑马灯效果)
  5. android设置Activity背景色为透明的2种方法
  6. android - TextView单行显示...或者文字左右滚动(走马灯效果)
  7. android中设置分隔线几种方法
  8. android 使用DigestUtilsmd5加密的方法
  9. Android getWindow().setFlags方法与SD卡权限

随机推荐

  1. broadcast基础
  2. Android(安卓)弹无虚发之第一弹:Android(
  3. Android进程优先级
  4. 【Android】基础篇:Android中TextView控件
  5. Android四大组件之广播接收器(一)
  6. Android(安卓)自定义 弹框日期选择器 弹
  7. Android(安卓)蓝牙打印指令
  8. App列表之圆角ListView(续)
  9. Android(安卓)圆形头像的两种实现方式
  10. Android(安卓)Bitmap的常用压缩方式