編輯:關於Android編程
package siso.multilistview; import android.os.Build; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; public class MainActivity extends AppCompatActivity implements View.OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); hideBothNavigationBarAndStatusBar(); setContentView(R.layout.activity_main); FloatMenuManager.getInstance().startFloatView(this.getApplicationContext()); findViewById(R.id.hideStatuBarNaviBar).setOnClickListener(this); } private void hideBothNavigationBarAndStatusBar() { View decorView = getWindow().getDecorView(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); } } @Override protected void onResume() { super.onResume(); hideBothNavigationBarAndStatusBar(); FloatMenuManager.getInstance().showFloatingView(); } @Override protected void onPause() { super.onPause(); FloatMenuManager.getInstance().hideFloatingView(); } @Override protected void onDestroy() { super.onDestroy(); FloatMenuManager.getInstance().destroy(); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.hideStatuBarNaviBar: hideBothNavigationBarAndStatusBar(); break; } } }
package siso.multilistview; public interface Const { String GAME_URL = "http://www.cnblogs.com/cate/html5/"; String HOME = "首頁"; String FAVOUR = "收藏"; String FEEDBACK = "客服"; String MESSAGE = "消息"; String CLOSE = "關閉"; String[] MENU_ITEMS = {HOME, FAVOUR, FEEDBACK, MESSAGE, CLOSE}; }
package siso.multilistview; import android.content.ComponentName; import android.content.Context; import android.os.IBinder; import java.io.ObjectStreamException; public class FloatMenuManager implements ServiceConnectionManager.QdServiceConnection { private ServiceConnectionManager mServiceConnectionManager; private FloatMenuManager() { } //靜態內部類實現單例 優於雙重檢查鎖(DCL)單例 public static FloatMenuManager getInstance() { return FloatMenuHolder.single; } /** * 靜態內部類能夠解決DCL雙重檢查鎖失效的問題 */ private static class FloatMenuHolder { private static final FloatMenuManager single = new FloatMenuManager(); } /** * 防止反序列獲取新的單例 * * @return * @throws ObjectStreamException */ private Object readResolve() throws ObjectStreamException { return FloatMenuHolder.single; } private FloatMenuService mFloatViewService; public void startFloatView(Context context) { if (mFloatViewService != null) { mFloatViewService.showFloat(); return; } if (mServiceConnectionManager == null) { mServiceConnectionManager = new ServiceConnectionManager(context, FloatMenuService.class, this); mServiceConnectionManager.bindToService(); } } /** */ public void addFloatMenuItem() { if (mFloatViewService != null) { } } /** * */ public void removeMenuItem() { if (mFloatViewService != null) { } } /** * 顯示懸浮圖標 */ public void showFloatingView() { if (mFloatViewService != null) { mFloatViewService.showFloat(); } } /** * 隱藏懸浮圖標 */ public void hideFloatingView() { if (mFloatViewService != null) { mFloatViewService.hideFloat(); } } /** * 釋放QDSDK數據 */ public void destroy() { if (mFloatViewService != null) { mFloatViewService.hideFloat(); mFloatViewService.destroyFloat(); } if (mServiceConnectionManager != null) { mServiceConnectionManager.unbindFromService(); } mFloatViewService = null; } @Override public void onServiceConnected(ComponentName name, IBinder service) { mFloatViewService = ((FloatMenuService.FloatMenuServiceBinder) service).getService(); if (mFloatViewService != null) { mFloatViewService.showFloat(); } } @Override public void onServiceDisconnected(ComponentName name) { mFloatViewService = null; } }
package siso.multilistview; import android.app.Service; import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Binder; import android.os.Handler; import android.os.IBinder; import android.view.View; import android.widget.Toast; import com.yw.game.sclib.Sc; import com.yw.game.sclib.ScCreateResultCallback; import java.util.ArrayList; import siso.floatmenu.FloatMenu; import siso.floatmenu.MenuItem; import siso.floatmenu.MenuItemView; public class FloatMenuService extends Service implements View.OnClickListener { private FloatMenu mFloatMenu; private final static String TAG = FloatMenuService.class.getSimpleName(); private Handler mHandler = new Handler(); private int[] menuIcons = new int[]{R.drawable.yw_menu_account, R.drawable.yw_menu_favour, R.drawable.yw_menu_fb, R.drawable.yw_menu_msg, R.drawable.yw_menu_close}; @Override public IBinder onBind(Intent intent) { return new FloatMenuServiceBinder(); } /** * On create. */ @Override public void onCreate() { super.onCreate(); ArrayList
package siso.multilistview; import android.app.Service; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.IBinder; public class ServiceConnectionManager implements ServiceConnection { private final Context context; private final Class service; private boolean attemptingToBind = false; private boolean bound = false; private QdServiceConnection mQdServiceConnection; public ServiceConnectionManager(Context context, Class service, QdServiceConnection mQdServiceConnection) { this.context = context; this.service = service; this.mQdServiceConnection = mQdServiceConnection; } public void bindToService() { if (!attemptingToBind) { attemptingToBind = true; context.bindService(new Intent(context, service), this, Context.BIND_AUTO_CREATE); } } @Override public void onServiceConnected(ComponentName componentName, IBinder iBinder) { attemptingToBind = false; bound = true; mQdServiceConnection.onServiceConnected(componentName, iBinder); } @Override public void onServiceDisconnected(ComponentName componentName) { mQdServiceConnection.onServiceDisconnected(componentName); bound = false; } public void unbindFromService() { attemptingToBind = false; if (bound) { context.unbindService(this); bound = false; } } public interface QdServiceConnection { void onServiceConnected(ComponentName name, IBinder service); void onServiceDisconnected(ComponentName name); } }
Android 側滑菜單的實現,參考網上的代碼,實現側滑菜單。最重要的是這個動畫類UgcAnimations,如何使用動畫類來側滑的封裝FlipperLayout。&nb
效果圖:程序列表:啟動程序,獲取程序信息: 代碼如下:創建一個AppInfo類來表示應用程序 public cla
前面已經學了activity的一些使用,那麼下面我們進行android中基本的控件的學習和使用。 1.android中的TextView控件 新建一個項目,項目名為UIT
TelephonyManager是一個管理手機通話狀態、電話網絡信息的服務類,該類提供了大量的getXxx(),方法獲取電話網絡的相關信息。 TelephonyManag