中華新聞
- 側(cè)邊欄
setContentView(R.layout.activity_main);
// 添加側(cè)邊欄
setBehindContentView(R.layout.left_menu);
SlidingMenu slidingMenu = getSlidingMenu();
// 全屏觸摸
slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
// 屏幕預(yù)留200像素
// 代碼適配
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
slidingMenu.setBehindOffset((int) (width * 0.625));
initFragment(); - 填充碎片
private void initFragment() {
// Fragment管理器
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();// 開(kāi)始事務(wù)
// 將幀布局替換為對(duì)應(yīng)的Fragment
transaction
.replace(R.id.fl_content, new ContentFragment(), TAG_CONTENT);
transaction.replace(R.id.fl_left_menu, new LeftMenuFragment(),
TAG_LEFT_MENU);
transaction.commit();// 提交事務(wù)
// fm.findFragmentByTag(TAG_CONTENT);
} - 事件的分發(fā)機(jī)制
分發(fā)機(jī)制 - 側(cè)邊欄有
第三方登入:
友盟+
Mob Android Single Sign-On (SSO)
跳轉(zhuǎn)到登入界面:
@Override
public void next_activity() {
// 跳轉(zhuǎn)到第二個(gè)界面
Intent intent = new Intent(this, SetUp2Activity.class);
startActivity(intent);
finish();
//執(zhí)行平移動(dòng)畫(huà)
//執(zhí)行界面切換動(dòng)畫(huà)的操作,是在startActivity或者finish之后執(zhí)行
//enterAnim : 新的界面進(jìn)入的動(dòng)畫(huà)
//exitAnim : 舊的界面退出的動(dòng)畫(huà)
overridePendingTransition(R.anim.setup_enter_next, R.anim.setup_exit_next);
}
動(dòng)畫(huà)效果:
setup_enter_next android:fromXDelta="100%" android:toXDelta="0"
setup_exit_next android:fromXDelta="0%" android:toXDelta="-100"
-
主頁(yè)
0. 整個(gè)是個(gè)viewPager
1. topBar
2. viewPagerIndicator(第三方工具)
3.子嵌套的viewPager,可以修改viewPager的源碼
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
this.getParent().requestDisallowInterceptTouchEvent(true);
return super.dispatchTouchEvent(ev);
}
3. listView
TextView ImgerView組成(3小時(shí)前)
有圖片就VISIBIbY,沒(méi)有圖片就GONE
4. PullToRefresh(沒(méi)有用到)
被Goggle官方出品的SwiperRefreshLayout(自動(dòng)刷新)代替啦,
好想是android5.0 出現(xiàn)的,知乎就是這的這個(gè)。
5. 加載數(shù)據(jù)
xutls中的htttpUtils
還有android自帶的HttpURLConnection(URLConnection的子類(lèi))
conn = (HttpURLConnection) new URL(url).openConnection();
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
conn.setRequestMethod("GET");
conn.connect();int code = conn.getResponseCode(); if (code == 200) { InputStream is = conn.getInputStream(); Bitmap bitmap = BitmapFactory.decodeStream(is); // 將圖片存到本地 localCacheUtils.setBitmapToLocal(bitmap, url); // 將圖片存到內(nèi)存 memoryCacheUtils.setBitmapToMemory(url, bitmap); return bitmap; } 6. 網(wǎng)絡(luò)請(qǐng)求哪家強(qiáng) 優(yōu)先推薦Retrofit, 需要遵循RESTful的風(fēng)格和能力掌握 Volley, 畢竟Volley你不需要做過(guò)度的封裝, 當(dāng)然不適合傳大數(shù)據(jù)(圖片)。 okHttp性能最高, 但是必須要做一些封裝。 ImagerLoader被Volley封裝 高效: OkHttp > Retrofit > Volley 健壯性: Retrofit > Volley > OkHttp 易用性: Volley > OkHttp > Retrofit 7. 圖片三級(jí)緩存機(jī)制 網(wǎng)絡(luò)緩存 public void getBitMapFormNet(ImageView iv, String url) { BitmapTask bitmap = new BitmapTask(); bitmap.execute(iv, url); } ** AsyncTask<Params, Progress, Result> ** class BitmapTask extends AsyncTask<Object, Integer, Bitmap> { private ImageView imageView; // 主線(xiàn)程, 預(yù)處理 @Override protected void onPreExecute() { super.onPreExecute(); } // 子線(xiàn)程運(yùn)行 @Override protected Bitmap doInBackground(Object... params) { imageView = (ImageView) params[0]; mUrl = (String) params[1]; // 設(shè)置標(biāo)識(shí) imageView.setTag(mUrl); return download(imageView, mUrl); } // 主線(xiàn)程運(yùn)行 @Override protected void onPostExecute(Bitmap result) { super.onPostExecute(result); if (result != null) { String url = (String) imageView.getTag(); if (mUrl.equals(url)) { imageView.setImageBitmap(result); System.out.println("從網(wǎng)絡(luò)中下載圖片成功!"); } } } // 主線(xiàn)程運(yùn)行, 進(jìn)度不斷更新方法 @Override protected void onProgressUpdate(Integer... values) { } } 8. 通過(guò)BitmapFactory解碼(獲取)Bitmap的幾種方式 **decodeFile()** //從SD卡文件讀取 **decodeResource()**//從資源文件res讀取 **decodeStream()** //從輸入流讀取 **decodeByteArray()** //從字節(jié)數(shù)組讀取 資訊
list_item下的 一個(gè)圖片 下面4個(gè)小圖片ListView包含不同Item的布局
1. 重寫(xiě) getViewTypeCount() – 該方法返回多少個(gè)不同的布局
2. 重寫(xiě) getItemViewType(int) – 根據(jù)position返回相應(yīng)的Item
3. 根據(jù)view item的類(lèi)型,在getView中創(chuàng)建正確的convertView城市
和資訊的布局一模一樣-
設(shè)置(了解)
builder.setTitle("字體設(shè)置");
String[] items = new String[] { "超大號(hào)字體", "大號(hào)字體", "正常字體", "小號(hào)字體",
"超小號(hào)字體" };
builder.setSingleChoiceItems(items, mSelectItem,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mCurrentItem = which;
}
});
builder.setPositiveButton("確定", new DialogInterface.OnClickListener() {@Override public void onClick(DialogInterface dialog, int which) { WebSettings settings = mWebView.getSettings(); switch (mCurrentItem) { case 0: settings.setTextSize(TextSize.LARGEST); break; case 1: settings.setTextSize(TextSize.LARGER); break; case 2: settings.setTextSize(TextSize.NORMAL); break; case 3: settings.setTextSize(TextSize.SMALLER); break; case 4: settings.setTextSize(TextSize.SMALLEST); break; default: break; } // 將最終選擇的狀態(tài)賦值給初始化狀態(tài) mSelectItem = mCurrentItem; } }); -
獲取緩存,清理緩存
PackageManager pm = getPackageManager();
//pm.getPackageSizeInfo("com.example.writecache", mStatsObserver);
/**
* 10-22 05:24:52.906: I/System.out(15794): cachesize:4.00KB codesize:0.96MB datasize:0.00B
*/
//反射獲取緩存
try {
Class<?> loadClass = MainActivity.class.getClassLoader().loadClass("android.content.pm.PackageManager");
Method method = loadClass.getDeclaredMethod("getPackageSizeInfo", String.class,IPackageStatsObserver.class);
//receiver : 類(lèi)的實(shí)例,隱藏參數(shù),方法不是靜態(tài)的必須指定
method.invoke(pm, "com.example.writecache",mStatsObserver);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}IPackageStatsObserver.Stub mStatsObserver = new IPackageStatsObserver.Stub() { public void onGetStatsCompleted(PackageStats stats, boolean succeeded) { long cachesize = stats.cacheSize;//緩存大小 long codesize = stats.codeSize;//應(yīng)用程序的大小 long datasize = stats.dataSize;//數(shù)據(jù)大小 String cache = Formatter.formatFileSize(getApplicationContext(), cachesize); String code = Formatter.formatFileSize(getApplicationContext(), codesize); String data = Formatter.formatFileSize(getApplicationContext(), datasize); System.out.println("cachesize:"+cache +" codesize:"+code+" datasize:"+data); } }; **權(quán)限 Android_UserPerssion_getPakeragerSize;** 獲取清理緩存(小妖)
1 遍歷getCacheDir下的所有文件,計(jì)算每個(gè)文件的大小即可
2 清除也是一樣,遍歷所有文件的大小,刪除即可
3 file.length() 返回的是文件的大小(單位b)新聞搜索(時(shí)間過(guò)長(zhǎng))
1 由于數(shù)據(jù)過(guò)大,應(yīng)該是服務(wù)器那邊的, 關(guān)鍵字查詢(xún)
2 服務(wù)器器會(huì)返回相關(guān)數(shù)據(jù)給我
3 里面的一些數(shù)據(jù), 基本是都是html的形式, 已經(jīng)排好.評(píng)論
1.沒(méi)什么作用
2.發(fā)現(xiàn)起始就是頭布局壓縮啦! 關(guān)于他的topBar-
Android 實(shí)現(xiàn)變色狀態(tài)欄
// 保留狀態(tài)的位置 <item name="android:fitsSystemWindows">true</item> Google 了之后在 Github 找到了一個(gè)開(kāi)源項(xiàng)目 【SystemBarTint】
Github開(kāi)源項(xiàng)目 SystemBarTint
自己封裝后
// 初始化窗體
@SuppressLint("ResourceAsColor")
@TargetApi(19)
private void initWindow() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
mTintManager = new SystemBarTintManager(this); // 色彩管理者
mColorPicker = new ColorPicker(this); // 獲取顏色采集器
// mTintManager.setStatusBarTintColor(R.color.main_color);
mTintManager.setStatusBarTintEnabled(true); // 設(shè)置狀態(tài)欄可用
int color = Color.argb(100, 255, 0, 0);
mTintManager.setTintColor(color); // 設(shè)置色彩顏色
}
}
關(guān)于(結(jié)束)
-
效仿QQ、微信、新浪的圓形頭像
- 將原圖居中裁剪成正方形
- 根據(jù)指定的寬度對(duì)正方形進(jìn)行縮放
- 裁剪成圓形
酒心網(wǎng)###
- 定位
定位方式#
gps一種定位方式
1.wifi定位,IP地址,根據(jù)你的IP地址獲取你的地理位置,精確度不是特別高了
2.基站定位,基站就是為電話(huà)服務(wù),信號(hào)的強(qiáng)弱決定了你離基站的距離,精確度比較高,幾十米--幾公里,精確度取決于基站的個(gè)數(shù)
wifi定位和基站定位局限性:不能定位海拔
3.gps定位,gps定位衛(wèi)星進(jìn)行定位,使用最少衛(wèi)星實(shí)現(xiàn)全球定位,去和
gps定位衛(wèi)星進(jìn)行通訊來(lái)獲取定位坐標(biāo),通過(guò)光波進(jìn)行通訊,必須得到
空曠地方才能進(jìn)行定位,連接至少需要一分鐘,耗電,精確度特別高,不
需要聯(lián)網(wǎng),聯(lián)網(wǎng):agps技術(shù),通過(guò)聯(lián)網(wǎng)來(lái)修正獲取的坐標(biāo),特別準(zhǔn)確的
百度定位sdk gps
高德 sdk
定位的具體代碼
android.permission.ACCESS_MOCK_LOCATION : 模擬位置的權(quán)限,模擬器中必須加的,真機(jī)可加可不加
android.permission.ACCESS_FINE_LOCATION : 精確位置的權(quán)限,真機(jī)必須添加
android.permission.ACCESS_COARSE_LOCATION : 大概位置的權(quán)限,真機(jī)必須添加
passive : 被動(dòng),基站定位
gps : gps定位
定位的步驟
1.獲取位置的管理者
//1.獲取位置的管理者
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
2.獲取定位方式
//2.獲取定位方式
//2.1獲取所有的定位方式
//enabledOnly : true : 返回所有可用的定位方式
List<String> providers = locationManager.getProviders(true);
for (String string : providers) {
System.out.println(string);
}
//2.2獲取最佳的定位方式
Criteria criteria = new Criteria();
criteria.setAltitudeRequired(true);//設(shè)置是否可以定位海拔,true:可以定位海拔,一定返回gps定位
//criteria : 設(shè)置定位的屬性,決定使用什么定位方式的
//enabledOnly : true : 定位可用的就返回
String bestProvider = locationManager.getBestProvider(criteria, true);
System.out.println("最佳的定位方式:"+bestProvider);
3.定位操作
a.定位
//provider : 定位方式
//minTime : 定位的最小時(shí)間間隔
//minDistance : 定位的最小距離間隔
//listener : LocationListener
locationManager.requestLocationUpdates(bestProvider, 0, 0, myLocationListener);
b.LocationListener
private class MyLocationListener implements LocationListener{
//當(dāng)定位位置改變的時(shí)候調(diào)用
//location : 當(dāng)前的位置
@Override
public void onLocationChanged(Location location) {
double latitude = location.getLatitude();//獲取緯度,平行
double longitude = location.getLongitude();//獲取經(jīng)度
textview.setText("longitude:"+longitude+" latitude:"+latitude);
}
//當(dāng)定位狀態(tài)改變的時(shí)候調(diào)用
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
//當(dāng)定位可用的時(shí)候調(diào)用
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
//當(dāng)定位不可用的時(shí)候調(diào)用
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
}
4.關(guān)閉gps定位
@Override
protected void onDestroy() {
super.onDestroy();
//關(guān)閉gps定位,高版本中已經(jīng)不能這么做了,高版本中規(guī)定關(guān)閉和開(kāi)啟gps必須交由用戶(hù)自己去實(shí)現(xiàn)
locationManager.removeUpdates(myLocationListener);
}
GPS定位城市需要做兩個(gè)步驟:
1、取得用戶(hù)當(dāng)前位置的經(jīng)度,緯度。
2、根據(jù)經(jīng)緯度轉(zhuǎn)換成城市名稱(chēng)。
經(jīng)緯度轉(zhuǎn)換成城市名稱(chēng),只能使用地圖服務(wù)了。自己做不來(lái)。
地圖服務(wù)API有兩個(gè),一個(gè)是百度地圖,一個(gè)是谷歌地圖。百度地圖API
調(diào)用需要注冊(cè)百度帳號(hào),并申請(qǐng)APP_KEY,谷歌地圖API直接調(diào)用即可。
百度地圖API調(diào)用地址:
http://api.map.baidu.com/geocoder?output=json&location=緯度,經(jīng)度&key=APP_KEY
QuickSideBar
幫助快速查閱對(duì)應(yīng)分組的側(cè)邊欄,可以配合任意列表,demo中給出配合RecyclerView(浮動(dòng)分組使用stickyheadersrecyclerview)。
項(xiàng)目地址:https://github.com/saiwu-bigkoo/Android-QuickSideBar
支付方式
-
窗體小控件
View contentView = View.inflate(getApplicationContext(), R.layout.popu_window, null);
//contentView : 顯示view對(duì)象
//width,height : view寬高
popupWindow = new PopupWindow(contentView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//4.獲取條目的位置,讓氣泡顯示在相應(yīng)的條目
int[] location = new int[2];//保存x和y坐標(biāo)的數(shù)組
view.getLocationInWindow(location);//獲取條目x和y的坐標(biāo),同時(shí)保存到int[]
//獲取x和y的坐標(biāo)
int x = location[0];
int y = location[1];
//parent : 要掛載在那個(gè)控件上
//gravity,x,y : 控制popuwindow顯示的位置
popupWindow.showAtLocation(parent, Gravity.LEFT | Gravity.TOP, x+50, y);隱藏氣泡 /** * 隱藏氣泡 */ private void hidePopuwindow() { if (popupWindow != null) { popupWindow.dismiss();//隱藏氣泡 popupWindow = null; } } //6.設(shè)置動(dòng)畫(huà) //縮放動(dòng)畫(huà) //前四個(gè) : 控制控件由沒(méi)有變到有 動(dòng)畫(huà) 0:沒(méi)有 1:整個(gè)控件 //后四個(gè):控制控件是按照自身還是父控件進(jìn)行變化 //RELATIVE_TO_SELF : 以自身變化 //RELATIVE_TO_PARENT : 以父控件變化 ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0.5f); scaleAnimation.setDuration(500); //漸變動(dòng)畫(huà) AlphaAnimation alphaAnimation = new AlphaAnimation(0.4f, 1.0f);//由半透明變成不透明 alphaAnimation.setDuration(500); //組合動(dòng)畫(huà) //shareInterpolator : 是否使用相同的動(dòng)畫(huà)插補(bǔ)器 true:共享 false:各自使用各自的 AnimationSet animationSet = new AnimationSet(true); //添加動(dòng)畫(huà) animationSet.addAnimation(scaleAnimation); animationSet.addAnimation(alphaAnimation); //執(zhí)行動(dòng)畫(huà) contentView.startAnimation(animationSet); 給popuwindow設(shè)置背景 popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
