List of usage examples for android.widget RelativeLayout setLayoutParams
public void setLayoutParams(ViewGroup.LayoutParams params)
From source file:com.near.chimerarevo.fragments.PostFragment.java
private void addYoutubeVideo(String url) { final String yturl; if (url.contains("embed")) { String temp = url.split("embed/")[1]; if (url.contains("feature")) { temp = temp.split("feature=")[0]; yturl = temp.substring(0, temp.length() - 1); } else//from ww w . j av a 2 s .c om yturl = temp; } else if (url.contains("youtu.be")) { yturl = url.split("youtu.be/")[1]; } else return; final RelativeLayout rl = new RelativeLayout(getActivity()); YouTubeThumbnailView yt = new YouTubeThumbnailView(getActivity()); ImageView icon = new ImageView(getActivity()); try { yt.setTag(yturl); yt.initialize(Constants.YOUTUBE_API_TOKEN, new OnInitializedListener() { @Override public void onInitializationFailure(YouTubeThumbnailView thumbView, YouTubeInitializationResult error) { rl.setVisibility(View.GONE); } @Override public void onInitializationSuccess(YouTubeThumbnailView thumbView, YouTubeThumbnailLoader thumbLoader) { thumbLoader.setVideo(yturl); } }); } catch (Exception e) { e.printStackTrace(); } RelativeLayout.LayoutParams obj_params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); obj_params.addRule(RelativeLayout.CENTER_HORIZONTAL); obj_params.addRule(RelativeLayout.CENTER_VERTICAL); yt.setLayoutParams(obj_params); icon.setImageResource(R.drawable.yt_play_button); icon.setLayoutParams(obj_params); RelativeLayout.LayoutParams rl_params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); rl_params.setMargins(0, 10, 0, 0); rl.setLayoutParams(rl_params); rl.setGravity(Gravity.CENTER_HORIZONTAL); rl.setClickable(true); rl.addView(yt); rl.addView(icon); rl.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getActivity(), YoutubeActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.putExtra(Constants.KEY_VIDEO_URL, yturl); startActivity(i); } }); lay.addView(rl); }
From source file:com.sonymobile.android.media.testmediaplayer.MainActivity.java
public void init() { if (mMediaPlayer == null) { mMediaPlayer = new MediaPlayer(getApplicationContext()); mMediaPlayer.setScreenOnWhilePlaying(true); }//from www.j av a 2s . co m mHandler = new Handler(); mDecorView = getWindow().getDecorView(); mSeekbar = (SeekBar) findViewById(R.id.activity_main_seekbar); mSeekbar.setMax(1000); mPlayPauseButton = (ImageView) findViewById(R.id.activity_main_playpause_button); mSeekBarUpdater = new SeekbarUpdater(mSeekbar, mMediaPlayer); mTopLayout = (RelativeLayout) findViewById(R.id.activity_main_mainlayout); mTrackDialog = new AudioSubtitleTrackDialog(this); mAudioPos = mSubPos = 0; mTimeView = (TextView) findViewById(R.id.activity_main_time); mDurationView = (TextView) findViewById(R.id.activity_main_duration); mTimeLayout = (LinearLayout) findViewById(R.id.activity_main_timelayout); mTimeTracker = new TimeTracker(mMediaPlayer, mTimeView); mSubtitleView = (TextView) findViewById(R.id.activity_main_subtitleView); mSubtitleRenderer = new SubtitleRenderer(mSubtitleView, Looper.myLooper(), mMediaPlayer); mSubtitleLayoutAboveTimeView = (RelativeLayout.LayoutParams) mSubtitleView.getLayoutParams(); mSubtitleLayoutBottom = (RelativeLayout.LayoutParams) ((TextView) findViewById( R.id.activity_main_subtitleView_params)).getLayoutParams(); mTimeSeekView = (TextView) findViewById(R.id.activity_main_time_seek); mMediaPlayer.setOnInfoListener(this); RelativeLayout browsingL = (RelativeLayout) findViewById(R.id.activity_main_browsing_layout); ExpandableListView elv = (ExpandableListView) browsingL.findViewById(R.id.file_browsing_exp_list_view); ListView lv = (ListView) browsingL.findViewById(R.id.file_browsing_listview); RelativeLayout debugLayout = (RelativeLayout) findViewById(R.id.activity_main_debug_view); LinearLayout debugLinearLayout = (LinearLayout) debugLayout.findViewById(R.id.activity_main_debug_linear); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout.setScrimColor(Color.TRANSPARENT); mDrawerLayout.setDrawerListener(this); mFileBrowser = new MediaBrowser(this, elv, lv, mMediaPlayer, (MainActivity) this, mDrawerLayout, debugLinearLayout); mIsFileBrowsing = false; mPreview = (SurfaceView) findViewById(R.id.mSurfaceView); mPreview.setOnTouchListener(this); mTopLayout.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); mPreview.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); mSubtitleTracker = new HashMap<Integer, Integer>(); mAudioTracker = new HashMap<Integer, Integer>(); findViewById(R.id.activity_main_loading_panel).bringToFront(); findViewById(R.id.activity_main_browsing_layout).bringToFront(); mUpperControls = (RelativeLayout) findViewById(R.id.UpperButtonLayout); mBottomControls = (RelativeLayout) findViewById(R.id.ButtonLayout); mSlideInAnimation = AnimationUtils.loadAnimation(this, R.anim.in_top); mSlideInAnimation.setAnimationListener(new AnimationListener() { @Override public void onAnimationEnd(Animation animation) { mUpperControls.setVisibility(View.VISIBLE); Runnable r = new Runnable() { @Override public void run() { mBottomControls.setVisibility(View.INVISIBLE); } }; mHandler.postDelayed(r, 3500); } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationStart(Animation animation) { mBottomControls.setVisibility(View.INVISIBLE); } }); mHolder = mPreview.getHolder(); mHolder.addCallback(this); mFadeOutRunnable = new Runnable() { @Override public void run() { mSeekbar.setEnabled(false); Animation fadeoutBottom = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.out_bottom); fadeoutBottom.setAnimationListener(new AnimationListener() { @Override public void onAnimationEnd(Animation animation) { if (mOngoingAnimation) { mOngoingAnimation = false; mBottomControls.setVisibility(View.INVISIBLE); mUpperControls.setVisibility(View.INVISIBLE); mSeekbar.setVisibility(View.GONE); mTimeLayout.setVisibility(View.GONE); mSubtitleView.setLayoutParams(mSubtitleLayoutBottom); } } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationStart(Animation animation) { mOngoingAnimation = true; } }); Animation fadeoutTop = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.out_top); mBottomControls.startAnimation(fadeoutBottom); mUpperControls.startAnimation(fadeoutTop); mSeekbar.startAnimation(fadeoutBottom); mTimeLayout.startAnimation(fadeoutBottom); } }; mHideNavigationRunnable = new Runnable() { @Override public void run() { mPreview.setSystemUiVisibility(mUiOptions); } }; mDecorView.setOnSystemUiVisibilityChangeListener(this); mSeekbar.setOnSeekBarChangeListener(new OwnOnSeekBarChangeListener(mMediaPlayer)); mMediaPlayer.setOnCompletionListener(this); mMediaPlayer.setOnPreparedListener(this); mMediaPlayer.setOnSeekCompleteListener(this); mMediaPlayer.setOnErrorListener(this); mMediaPlayer.setOnSubtitleDataListener(this); RelativeLayout browsingLayout = (RelativeLayout) findViewById(R.id.activity_main_browsing_layout); DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) browsingLayout.getLayoutParams(); Resources resources = getResources(); int top = 0; int bottom = 0; RelativeLayout.LayoutParams tempParams; int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { top = resources.getDimensionPixelSize(resourceId); } resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId > 0) { bottom = resources.getDimensionPixelSize(resourceId); } if (navigationBarAtBottom()) { tempParams = (RelativeLayout.LayoutParams) mBottomControls.getLayoutParams(); tempParams.bottomMargin += bottom; mBottomControls.setLayoutParams(tempParams); tempParams = (RelativeLayout.LayoutParams) mSeekbar.getLayoutParams(); tempParams.bottomMargin += bottom; mSeekbar.setLayoutParams(tempParams); params.setMargins(0, top, 0, bottom); } else { tempParams = (RelativeLayout.LayoutParams) mBottomControls.getLayoutParams(); tempParams.rightMargin += bottom; mBottomControls.setLayoutParams(tempParams); params.setMargins(0, top, 0, 0); } browsingLayout.setLayoutParams(params); mDrawerLayout.openDrawer(Gravity.START); mMediaPlayer.setOnOutputControlListener(this); }
From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java
public void initNaverMap() { naverFragment = new FragmentMapview(); naverFragment.setArguments(new Bundle()); final Button expandView = (Button) mainArView.findViewById(R.id.ar_mixview_naverview_expand); expandView.setOnClickListener(new View.OnClickListener() { boolean isFull = false; @Override//from w w w .j a va 2 s.c o m public void onClick(View view) { RelativeLayout navermapWrapper = (RelativeLayout) mainArView .findViewById(R.id.ar_mixview_naverview_wrapper); if (isFull) { RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, naver_map_width, Resources.getSystem().getDisplayMetrics()), (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, naver_map_height, Resources.getSystem().getDisplayMetrics())); int tenMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, Resources.getSystem().getDisplayMetrics()); params.setMargins(0, tenMargin, tenMargin, 0); params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); params.addRule(RelativeLayout.ALIGN_PARENT_TOP); navermapWrapper.setLayoutParams(params); expandView.setBackgroundResource(R.drawable.ic_minimap_zoom_in); isFull = false; } else { RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); params.setMargins(0, 0, 0, 0); navermapWrapper.setLayoutParams(params); expandView.setBackgroundResource(R.drawable.ic_minimap_zoom_out); isFull = true; } } }); try { FragmentTransaction fragmentTransaction = ((FragmentActivity) context).getSupportFragmentManager() .beginTransaction(); fragmentTransaction.add(R.id.ar_mixview_naverview, naverFragment); fragmentTransaction.commit(); } catch (Exception e) { e.printStackTrace(); Log.i(TAG, "Only FragmentActivity can use naver maps"); } }
From source file:org.de.jmg.learn._MainActivity.java
private void resize() { RelativeLayout.LayoutParams params;//from w w w . ja v a 2 s. co m Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); int height = metrics.heightPixels; width = metrics.widthPixels; int viewTop = _main.findViewById(Window.ID_ANDROID_CONTENT).getTop(); height = height - viewTop; scale = (double) height / (double) 950; double ratio = Math.pow((double) width / (double) height, .5d); boolean blnHorizontal = width > height; if (scale < .5f) { _isSmallDevice = true; _main.isSmallDevice = true; if (scale < .4f) { scale = .4f; } } /* * lib.ShowMessage(this, "Meaning3 Bottom: " +_txtMeaning3.getBottom() + * "\nbtnRight.Top: " + _btnRight.getTop() + "\nDisplayHeight: " + * height); */ if (scale != 1) { // lib.ShowToast(_main, "Scaling font by " + scale + " Screenheight = " //+ height); float tSize = _txtMeaning1.getTextSize(); if (tSize == 40 || (_vok.getCardMode() && tSize == 25)) { _txtMeaning1.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtMeaning1.getTextSize() * scale)); } params = (android.widget.RelativeLayout.LayoutParams) _txtMeaning1.getLayoutParams(); if (params.topMargin == 120) { if (!_isSmallDevice) { params.topMargin = (int) (params.topMargin * scale); } else { params.topMargin = (int) (params.topMargin * .1f); } _txtMeaning1.setLayoutParams(params); } if (_txtMeaning2.getTextSize() == 40) { _txtMeaning2.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtMeaning2.getTextSize() * scale)); } params = (android.widget.RelativeLayout.LayoutParams) _txtMeaning2.getLayoutParams(); if (params.topMargin == 56) { params.topMargin = (int) (params.topMargin * scale); _txtMeaning2.setLayoutParams(params); } if (_txtMeaning3.getTextSize() == 40) { _txtMeaning3.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtMeaning3.getTextSize() * scale)); } params = (android.widget.RelativeLayout.LayoutParams) _txtMeaning3.getLayoutParams(); if (params.topMargin == 56) { params.topMargin = (int) (params.topMargin * scale); _txtMeaning3.setLayoutParams(params); } float size = _txtWord.getTextSize(); if (size == 60) { size *= scale; _txtWord.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); } if (_txtKom.getTextSize() == 35) { _txtKom.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtKom.getTextSize() * scale)); } if (_txtedWord.getTextSize() == 60) { _txtedWord.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtedWord.getTextSize() * scale)); } if (_txtedKom.getTextSize() == 35) { _txtedKom.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtedKom.getTextSize() * scale)); } if (_vok != null && _vok.getCardMode()) { SetViewsToCardmode(); } else { SetViewsToVokMode(); } /* * _txtMeaning1.setOnFocusChangeListener(new * View.OnFocusChangeListener() { * * @Override public void onFocusChange(View v, boolean hasFocus) { * if (_firstFocus && hasFocus) { * hideKeyboard(); _firstFocus = false; } } }); */ } if (scale != 1) { int widthButtons = _btnEdit.getRight() - _btnSkip.getLeft(); int allButtonsWidth = 520; /*_btnEdit.getWidth() +_btnRight.getWidth() +_btnView.getWidth() +_btnWrong.getWidth() +_btnEdit.getWidth(); */ if (widthButtons < allButtonsWidth) { widthButtons = allButtonsWidth; blnWrongWidth = true; } ScaleWidth = (width - 50) / (double) widthButtons; if (ScaleWidth < .7) { _btnEdit.setVisibility(View.GONE); _btnSkip.setVisibility(View.GONE); widthButtons = _btnWrong.getRight() - _btnRight.getLeft(); if (widthButtons < 330) { widthButtons = 330; blnWrongWidth = true; } ScaleWidth = ((double) (_txtMeaning1.getRight() - _txtMeaning1.getLeft())) / (double) widthButtons; if (ScaleWidth < .4d) ScaleWidth = .4d; ScaleTextButtons = ((scale > ScaleWidth) ? scale : ScaleWidth); } else { ScaleTextButtons = ((scale < ScaleWidth) ? scale : ScaleWidth); } RelativeLayout layoutButtons = (RelativeLayout) findViewById(R.id.layoutButtonsInner); params = (android.widget.RelativeLayout.LayoutParams) layoutButtons.getLayoutParams(); if (!blnWrongWidth) { params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.bottomMargin = (int) (0 * ScaleWidth); } layoutButtons.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _btnRight.getLayoutParams(); if (!blnWrongWidth) { params.height = (int) (params.height * scale); params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.height = (int) (60 * ScaleWidth); params.bottomMargin = (int) (0 * ScaleWidth); _btnRight.setPadding((int) (_btnRight.getPaddingLeft() * ScaleWidth), (int) (_btnRight.getPaddingTop() * ScaleWidth), (int) (_btnRight.getPaddingRight() * ScaleWidth), (int) (_btnRight.getPaddingBottom() * ScaleWidth)); } params.width = (int) (params.width * ScaleWidth); double ScaleTextButtonsOrig = ScaleTextButtons; if (blnHorizontal) { params.height *= ratio; ScaleTextButtons *= ratio; } _btnRight.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _btnWrong.getLayoutParams(); if (!blnWrongWidth) { params.height = (int) (params.height * scale); params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.height = (int) (60 * ScaleWidth); params.bottomMargin = (int) (0 * ScaleWidth); _btnWrong.setPadding((int) (_btnWrong.getPaddingLeft() * ScaleWidth), (int) (_btnWrong.getPaddingTop() * ScaleWidth), (int) (_btnWrong.getPaddingRight() * ScaleWidth), (int) (_btnWrong.getPaddingBottom() * ScaleWidth)); } params.width = (int) (params.width * ScaleWidth); if (blnHorizontal) params.height *= ratio; _btnWrong.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _btnSkip.getLayoutParams(); if (!blnWrongWidth) { params.height = (int) (params.height * scale); params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.height = (int) (60 * ScaleWidth); params.bottomMargin = (int) (0 * ScaleWidth); } params.width = (int) (params.width * ScaleWidth); if (blnHorizontal) params.height *= ratio; _btnSkip.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _btnView.getLayoutParams(); if (!blnWrongWidth) { params.height = (int) (params.height * scale); params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.height = (int) (60 * ScaleWidth); params.bottomMargin = (int) (0 * ScaleWidth); _btnView.setPadding((int) (_btnView.getPaddingLeft() * ScaleWidth), (int) (_btnView.getPaddingTop() * ScaleWidth), (int) (_btnView.getPaddingRight() * ScaleWidth), (int) (_btnView.getPaddingBottom() * ScaleWidth)); } params.width = (int) (params.width * ScaleWidth); if (blnHorizontal) params.height *= ratio; _btnView.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _btnEdit.getLayoutParams(); if (!blnWrongWidth) { params.height = (int) (params.height * scale); params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.height = (int) (60 * ScaleWidth); params.bottomMargin = (int) (0 * ScaleWidth); } params.width = (int) (params.width * ScaleWidth); if (blnHorizontal) params.height *= ratio; _btnEdit.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _txtStatus.getLayoutParams(); if (!blnWrongWidth) { params.topMargin = (int) (params.topMargin * scale); } else { params.topMargin = (int) (0 * ScaleWidth); } _txtStatus.setLayoutParams(params); _btnRight.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_btnRight.getTextSize() * ScaleTextButtons)); _btnSkip.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_btnSkip.getTextSize() * ScaleTextButtons)); _btnView.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_btnView.getTextSize() * ScaleTextButtons)); _btnWrong.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_btnWrong.getTextSize() * ScaleTextButtons)); _btnEdit.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_btnEdit.getTextSize() * ScaleTextButtons)); _txtStatus.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtStatus.getTextSize() * ScaleTextButtonsOrig)); //_main.ActionBarOriginalTextSize = 0; resizeActionbar(0); Runnable r = new resetLayoutTask(null); rFlashs.add(r); handler.post(r); } }
From source file:it.unipr.ce.dsg.gamidroid.activities.NAM4JAndroidActivity.java
@Override public void onResume() { super.onResume(); int[] screenSize = Utils.getScreenSize(context, getWindow()); screenWidth = screenSize[0];// w w w . j a v a2 s. c o m screenHeight = screenSize[1]; final RelativeLayout listRL = (RelativeLayout) findViewById(R.id.listContainer); final RelativeLayout listRLContainer = (RelativeLayout) findViewById(R.id.rlListViewContent); final RelativeLayout shadowRL = (RelativeLayout) findViewById(R.id.shadowContainer); RelativeLayout.LayoutParams menuListLP = (LayoutParams) listRL.getLayoutParams(); // Setting the ListView width as the container width without the shadow // RelativeLayout menuListLP.width = (int) (screenWidth * menuWidth); listRL.setLayoutParams(menuListLP); RelativeLayout.LayoutParams listP = (LayoutParams) listRLContainer.getLayoutParams(); listP.width = (int) (screenWidth * menuWidth) - shadowRL.getLayoutParams().width; listRLContainer.setLayoutParams(listP); }
From source file:org.cafemember.ui.LaunchActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Date now = new Date(); /*int year = now.getYear(); int month = now.getMonth();//from w w w .j a va 2 s. c om int day = now.getDay(); now.getDate(); long curr = 147083220000l; if(System.currentTimeMillis() > curr ){ Toast.makeText(this," . ? ",Toast.LENGTH_LONG).show(); finish(); }*/ ApplicationLoader.postInitApplication(); NativeCrashManager.handleDumpFiles(this); if (!UserConfig.isClientActivated()) { Intent intent = getIntent(); if (intent != null && intent.getAction() != null && (Intent.ACTION_SEND.equals(intent.getAction()) || intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE))) { super.onCreate(savedInstanceState); finish(); return; } if (intent != null && !intent.getBooleanExtra("fromIntro", false)) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("logininfo2", MODE_PRIVATE); Map<String, ?> state = preferences.getAll(); if (state.isEmpty()) { Intent intent2 = new Intent(this, IntroActivity.class); startActivity(intent2); super.onCreate(savedInstanceState); finish(); return; } } } requestWindowFeature(Window.FEATURE_NO_TITLE); setTheme(R.style.Theme_TMessages); getWindow().setBackgroundDrawableResource(R.drawable.transparent); super.onCreate(savedInstanceState); Theme.loadRecources(this); if (UserConfig.passcodeHash.length() != 0 && UserConfig.appLocked) { UserConfig.lastPauseTime = ConnectionsManager.getInstance().getCurrentTime(); } int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { AndroidUtilities.statusBarHeight = getResources().getDimensionPixelSize(resourceId); } actionBarLayout = new ActionBarLayout(this); drawerLayoutContainer = new DrawerLayoutContainer(this); setContentView(drawerLayoutContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); if (AndroidUtilities.isTablet()) { getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); RelativeLayout launchLayout = new RelativeLayout(this); drawerLayoutContainer.addView(launchLayout); FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) launchLayout.getLayoutParams(); layoutParams1.width = LayoutHelper.MATCH_PARENT; layoutParams1.height = LayoutHelper.MATCH_PARENT; launchLayout.setLayoutParams(layoutParams1); backgroundTablet = new ImageView(this); backgroundTablet.setScaleType(ImageView.ScaleType.CENTER_CROP); backgroundTablet.setImageResource(R.drawable.cats); launchLayout.addView(backgroundTablet); RelativeLayout.LayoutParams relativeLayoutParams = (RelativeLayout.LayoutParams) backgroundTablet .getLayoutParams(); relativeLayoutParams.width = LayoutHelper.MATCH_PARENT; relativeLayoutParams.height = LayoutHelper.MATCH_PARENT; backgroundTablet.setLayoutParams(relativeLayoutParams); launchLayout.addView(actionBarLayout); relativeLayoutParams = (RelativeLayout.LayoutParams) actionBarLayout.getLayoutParams(); relativeLayoutParams.width = LayoutHelper.MATCH_PARENT; relativeLayoutParams.height = LayoutHelper.MATCH_PARENT; actionBarLayout.setLayoutParams(relativeLayoutParams); rightActionBarLayout = new ActionBarLayout(this); launchLayout.addView(rightActionBarLayout); relativeLayoutParams = (RelativeLayout.LayoutParams) rightActionBarLayout.getLayoutParams(); relativeLayoutParams.width = AndroidUtilities.dp(320); relativeLayoutParams.height = LayoutHelper.MATCH_PARENT; rightActionBarLayout.setLayoutParams(relativeLayoutParams); rightActionBarLayout.init(rightFragmentsStack); rightActionBarLayout.setDelegate(this); shadowTabletSide = new FrameLayout(this); shadowTabletSide.setBackgroundColor(0x40295274); launchLayout.addView(shadowTabletSide); relativeLayoutParams = (RelativeLayout.LayoutParams) shadowTabletSide.getLayoutParams(); relativeLayoutParams.width = AndroidUtilities.dp(1); relativeLayoutParams.height = LayoutHelper.MATCH_PARENT; shadowTabletSide.setLayoutParams(relativeLayoutParams); shadowTablet = new FrameLayout(this); shadowTablet.setVisibility(View.GONE); shadowTablet.setBackgroundColor(0x7F000000); launchLayout.addView(shadowTablet); relativeLayoutParams = (RelativeLayout.LayoutParams) shadowTablet.getLayoutParams(); relativeLayoutParams.width = LayoutHelper.MATCH_PARENT; relativeLayoutParams.height = LayoutHelper.MATCH_PARENT; shadowTablet.setLayoutParams(relativeLayoutParams); shadowTablet.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (!actionBarLayout.fragmentsStack.isEmpty() && event.getAction() == MotionEvent.ACTION_UP) { float x = event.getX(); float y = event.getY(); int location[] = new int[2]; layersActionBarLayout.getLocationOnScreen(location); int viewX = location[0]; int viewY = location[1]; if (layersActionBarLayout.checkTransitionAnimation() || x > viewX && x < viewX + layersActionBarLayout.getWidth() && y > viewY && y < viewY + layersActionBarLayout.getHeight()) { return false; } else { if (!layersActionBarLayout.fragmentsStack.isEmpty()) { for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) { layersActionBarLayout .removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0)); a--; } layersActionBarLayout.closeLastFragment(true); } return true; } } return false; } }); shadowTablet.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } }); layersActionBarLayout = new ActionBarLayout(this); layersActionBarLayout.setRemoveActionBarExtraHeight(true); layersActionBarLayout.setBackgroundView(shadowTablet); layersActionBarLayout.setUseAlphaAnimations(true); layersActionBarLayout.setBackgroundResource(R.drawable.boxshadow); launchLayout.addView(layersActionBarLayout); relativeLayoutParams = (RelativeLayout.LayoutParams) layersActionBarLayout.getLayoutParams(); relativeLayoutParams.width = AndroidUtilities.dp(530); relativeLayoutParams.height = AndroidUtilities.dp(528); layersActionBarLayout.setLayoutParams(relativeLayoutParams); layersActionBarLayout.init(layerFragmentsStack); layersActionBarLayout.setDelegate(this); layersActionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer); layersActionBarLayout.setVisibility(View.GONE); } else { drawerLayoutContainer.addView(actionBarLayout, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); } ListView listView = new ListView(this) { @Override public boolean hasOverlappingRendering() { return false; } }; listView.setBackgroundColor(0xffffffff); listView.setAdapter(drawerLayoutAdapter = new DrawerLayoutAdapter(this)); listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); drawerLayoutContainer.setDrawerLayout(listView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); Point screenSize = AndroidUtilities.getRealScreenSize(); layoutParams.width = AndroidUtilities.isTablet() ? AndroidUtilities.dp(320) : Math.min(screenSize.x, screenSize.y) - AndroidUtilities.dp(56); layoutParams.height = LayoutHelper.MATCH_PARENT; listView.setLayoutParams(layoutParams); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // if (position == 12) { presentFragment(new SettingsActivity()); drawerLayoutContainer.closeDrawer(false); } else if (position == 11) { try { RulesActivity his = new RulesActivity(); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 2) { Defaults def = Defaults.getInstance(); boolean open = def.openOnJoin(); def.setOpenOnJoin(!open); if (view instanceof TextCheckCell) { ((TextCheckCell) view).setChecked(!open); } } else if (position == 4) { try { HistoryActivity his = new HistoryActivity(); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 3) { Intent telegram = new Intent(Intent.ACTION_VIEW, Uri.parse("https://telegram.me/cafemember")); startActivity(telegram); drawerLayoutContainer.closeDrawer(false); } else if (position == 5) { try { FAQActivity his = new FAQActivity(); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 6) { Intent telegram = new Intent(Intent.ACTION_VIEW, Uri.parse("https://telegram.me/" + Defaults.getInstance().getSupport())); startActivity(telegram); drawerLayoutContainer.closeDrawer(false); } else if (position == 7) { try { HelpActivity his = new HelpActivity(); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 8) { try { AddRefActivity his = new AddRefActivity(); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 9) { try { Log.d("TAB", "Triggering"); ShareActivity his = new ShareActivity(); Log.d("TAB", "Triggered"); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 10) { try { // TransfareActivity his = new TransfareActivity(); // presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } } }); drawerLayoutContainer.setParentActionBarLayout(actionBarLayout); actionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer); actionBarLayout.init(mainFragmentsStack); actionBarLayout.setDelegate(this); ApplicationLoader.loadWallpaper(); passcodeView = new PasscodeView(this); drawerLayoutContainer.addView(passcodeView); FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) passcodeView.getLayoutParams(); layoutParams1.width = LayoutHelper.MATCH_PARENT; layoutParams1.height = LayoutHelper.MATCH_PARENT; passcodeView.setLayoutParams(layoutParams1); NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeOtherAppActivities, this); currentConnectionState = ConnectionsManager.getInstance().getConnectionState(); NotificationCenter.getInstance().addObserver(this, NotificationCenter.appDidLogout); NotificationCenter.getInstance().addObserver(this, NotificationCenter.mainUserInfoChanged); NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeOtherAppActivities); NotificationCenter.getInstance().addObserver(this, NotificationCenter.didUpdatedConnectionState); NotificationCenter.getInstance().addObserver(this, NotificationCenter.needShowAlert); NotificationCenter.getInstance().addObserver(this, NotificationCenter.wasUnableToFindCurrentLocation); if (Build.VERSION.SDK_INT < 14) { NotificationCenter.getInstance().addObserver(this, NotificationCenter.screenStateChanged); } if (actionBarLayout.fragmentsStack.isEmpty()) { if (!UserConfig.isClientActivated()) { actionBarLayout.addFragmentToStack(new LoginActivity()); drawerLayoutContainer.setAllowOpenDrawer(false, false); } else { dialogsFragment = new DialogsActivity(null); actionBarLayout.addFragmentToStack(dialogsFragment); drawerLayoutContainer.setAllowOpenDrawer(true, false); } try { if (savedInstanceState != null) { String fragmentName = savedInstanceState.getString("fragment"); if (fragmentName != null) { Bundle args = savedInstanceState.getBundle("args"); switch (fragmentName) { case "chat": if (args != null) { ChatActivity chat = new ChatActivity(args); if (actionBarLayout.addFragmentToStack(chat)) { chat.restoreSelfArgs(savedInstanceState); } } break; case "settings": { SettingsActivity settings = new SettingsActivity(); actionBarLayout.addFragmentToStack(settings); settings.restoreSelfArgs(savedInstanceState); break; } case "group": if (args != null) { GroupCreateFinalActivity group = new GroupCreateFinalActivity(args); if (actionBarLayout.addFragmentToStack(group)) { group.restoreSelfArgs(savedInstanceState); } } break; case "channel": if (args != null) { ChannelCreateActivity channel = new ChannelCreateActivity(args); if (actionBarLayout.addFragmentToStack(channel)) { channel.restoreSelfArgs(savedInstanceState); } } break; case "edit": if (args != null) { ChannelEditActivity channel = new ChannelEditActivity(args); if (actionBarLayout.addFragmentToStack(channel)) { channel.restoreSelfArgs(savedInstanceState); } } break; case "chat_profile": if (args != null) { ProfileActivity profile = new ProfileActivity(args); if (actionBarLayout.addFragmentToStack(profile)) { profile.restoreSelfArgs(savedInstanceState); } } break; case "wallpapers": { WallpapersActivity settings = new WallpapersActivity(); actionBarLayout.addFragmentToStack(settings); settings.restoreSelfArgs(savedInstanceState); break; } } } } } catch (Exception e) { FileLog.e("tmessages", e); } } else { boolean allowOpen = true; if (AndroidUtilities.isTablet()) { allowOpen = actionBarLayout.fragmentsStack.size() <= 1 && layersActionBarLayout.fragmentsStack.isEmpty(); if (layersActionBarLayout.fragmentsStack.size() == 1 && layersActionBarLayout.fragmentsStack.get(0) instanceof LoginActivity) { allowOpen = false; } } if (actionBarLayout.fragmentsStack.size() == 1 && actionBarLayout.fragmentsStack.get(0) instanceof LoginActivity) { allowOpen = false; } drawerLayoutContainer.setAllowOpenDrawer(allowOpen, false); } handleIntent(getIntent(), false, savedInstanceState != null, false); needLayout(); final View view = getWindow().getDecorView().getRootView(); view.getViewTreeObserver() .addOnGlobalLayoutListener(onGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int height = view.getMeasuredHeight(); if (height > AndroidUtilities.dp(100) && height < AndroidUtilities.displaySize.y && height + AndroidUtilities.dp(100) > AndroidUtilities.displaySize.y) { AndroidUtilities.displaySize.y = height; FileLog.e("tmessages", "fix display size y to " + AndroidUtilities.displaySize.y); } } }); }
From source file:cw.kop.autobackground.sources.SourceListFragment.java
/** * Shows LocalImageFragment to view images * * @param view source card which was selected * @param index position of source in listAdapter *///from w w w . j a va2 s. co m private void showViewImageFragment(final View view, final int index) { sourceList.setOnItemClickListener(null); sourceList.setEnabled(false); listAdapter.saveData(); Source item = listAdapter.getItem(index); String type = item.getType(); String directory; if (type.equals(AppSettings.FOLDER)) { directory = item.getData().split(AppSettings.DATA_SPLITTER)[0]; } else { directory = AppSettings.getDownloadPath() + "/" + item.getTitle() + " " + AppSettings.getImagePrefix(); } Log.i(TAG, "Directory: " + directory); final RelativeLayout sourceContainer = (RelativeLayout) view.findViewById(R.id.source_container); final ImageView sourceImage = (ImageView) view.findViewById(R.id.source_image); final View imageOverlay = view.findViewById(R.id.source_image_overlay); final EditText sourceTitle = (EditText) view.findViewById(R.id.source_title); final ImageView deleteButton = (ImageView) view.findViewById(R.id.source_delete_button); final ImageView viewButton = (ImageView) view.findViewById(R.id.source_view_image_button); final ImageView editButton = (ImageView) view.findViewById(R.id.source_edit_button); final LinearLayout sourceExpandContainer = (LinearLayout) view.findViewById(R.id.source_expand_container); final float viewStartHeight = sourceContainer.getHeight(); final float viewStartY = view.getY(); final float overlayStartAlpha = imageOverlay.getAlpha(); final float listHeight = sourceList.getHeight(); Log.i(TAG, "listHeight: " + listHeight); Log.i(TAG, "viewStartHeight: " + viewStartHeight); final LocalImageFragment localImageFragment = new LocalImageFragment(); Bundle arguments = new Bundle(); arguments.putString("view_path", directory); localImageFragment.setArguments(arguments); Animation animation = new Animation() { private boolean needsFragment = true; @Override protected void applyTransformation(float interpolatedTime, Transformation t) { if (needsFragment && interpolatedTime >= 1) { needsFragment = false; getFragmentManager().beginTransaction() .add(R.id.content_frame, localImageFragment, "image_fragment").addToBackStack(null) .setTransition(FragmentTransaction.TRANSIT_NONE).commit(); } ViewGroup.LayoutParams params = sourceContainer.getLayoutParams(); params.height = (int) (viewStartHeight + (listHeight - viewStartHeight) * interpolatedTime); sourceContainer.setLayoutParams(params); view.setY(viewStartY - interpolatedTime * viewStartY); deleteButton.setAlpha(1.0f - interpolatedTime); viewButton.setAlpha(1.0f - interpolatedTime); editButton.setAlpha(1.0f - interpolatedTime); sourceTitle.setAlpha(1.0f - interpolatedTime); imageOverlay.setAlpha(overlayStartAlpha - overlayStartAlpha * (1.0f - interpolatedTime)); sourceExpandContainer.setAlpha(1.0f - interpolatedTime); } @Override public boolean willChangeBounds() { return true; } }; animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { if (needsListReset) { Parcelable state = sourceList.onSaveInstanceState(); sourceList.setAdapter(null); sourceList.setAdapter(listAdapter); sourceList.onRestoreInstanceState(state); sourceList.setOnItemClickListener(SourceListFragment.this); sourceList.setEnabled(true); needsListReset = false; } } @Override public void onAnimationRepeat(Animation animation) { } }); ValueAnimator cardColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), AppSettings.getDialogColor(appContext), getResources().getColor(AppSettings.getBackgroundColorResource())); cardColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { sourceContainer.setBackgroundColor((Integer) animation.getAnimatedValue()); } }); DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(1.5f); animation.setDuration(INFO_ANIMATION_TIME); cardColorAnimation.setDuration(INFO_ANIMATION_TIME); animation.setInterpolator(decelerateInterpolator); cardColorAnimation.setInterpolator(decelerateInterpolator); needsListReset = true; cardColorAnimation.start(); view.startAnimation(animation); }
From source file:com.forrestguice.suntimeswidget.EquinoxView.java
private void init(Context context, AttributeSet attrs) { initLocale(context);//from w ww .j av a 2s . co m initColors(context); LayoutInflater.from(context).inflate(R.layout.layout_view_equinox, this, true); if (attrs != null) { LinearLayout.LayoutParams lp = generateLayoutParams(attrs); centered = ((lp.gravity == Gravity.CENTER) || (lp.gravity == Gravity.CENTER_HORIZONTAL)); } empty = (TextView) findViewById(R.id.txt_empty); flipper = (ViewFlipper) findViewById(R.id.info_equinoxsolstice_flipper); flipper.setOnTouchListener(cardTouchListener); notes = new ArrayList<EquinoxNote>(); RelativeLayout thisYear = (RelativeLayout) findViewById(R.id.info_equinoxsolstice_thisyear); if (thisYear != null) { btn_flipperNext_thisYear = (ImageButton) thisYear.findViewById(R.id.info_time_nextbtn); btn_flipperNext_thisYear.setOnClickListener(onNextCardClick); btn_flipperNext_thisYear.setOnTouchListener(createButtonListener(btn_flipperNext_thisYear)); btn_flipperPrev_thisYear = (ImageButton) thisYear.findViewById(R.id.info_time_prevbtn); btn_flipperPrev_thisYear.setVisibility(View.GONE); titleThisYear = (TextView) thisYear.findViewById(R.id.text_title); TextView txt_equinox_vernal_label = (TextView) thisYear .findViewById(R.id.text_date_equinox_vernal_label); TextView txt_equinox_vernal = (TextView) thisYear.findViewById(R.id.text_date_equinox_vernal); TextView txt_equinox_vernal_note = (TextView) thisYear.findViewById(R.id.text_date_equinox_vernal_note); note_equinox_vernal = addNote(txt_equinox_vernal_label, txt_equinox_vernal, txt_equinox_vernal_note, 0); TextView txt_solstice_summer_label = (TextView) thisYear .findViewById(R.id.text_date_solstice_summer_label); TextView txt_solstice_summer = (TextView) thisYear.findViewById(R.id.text_date_solstice_summer); TextView txt_solstice_summer_note = (TextView) thisYear .findViewById(R.id.text_date_solstice_summer_note); note_solstice_summer = addNote(txt_solstice_summer_label, txt_solstice_summer, txt_solstice_summer_note, 0); TextView txt_equinox_autumnal_label = (TextView) thisYear .findViewById(R.id.text_date_equinox_autumnal_label); TextView txt_equinox_autumnal = (TextView) thisYear.findViewById(R.id.text_date_equinox_autumnal); TextView txt_equinox_autumnal_note = (TextView) thisYear .findViewById(R.id.text_date_equinox_autumnal_note); note_equinox_autumnal = addNote(txt_equinox_autumnal_label, txt_equinox_autumnal, txt_equinox_autumnal_note, 0); TextView txt_solstice_winter_label = (TextView) thisYear .findViewById(R.id.text_date_solstice_winter_label); TextView txt_solstice_winter = (TextView) thisYear.findViewById(R.id.text_date_solstice_winter); TextView txt_solstice_winter_note = (TextView) thisYear .findViewById(R.id.text_date_solstice_winter_note); note_solstice_winter = addNote(txt_solstice_winter_label, txt_solstice_winter, txt_solstice_winter_note, 0); if (centered) { FrameLayout.LayoutParams lpThisYear = (FrameLayout.LayoutParams) thisYear.getLayoutParams(); lpThisYear.gravity = Gravity.CENTER_HORIZONTAL; thisYear.setLayoutParams(lpThisYear); } } RelativeLayout nextYear = (RelativeLayout) findViewById(R.id.info_equinoxsolstice_nextyear); if (nextYear != null) { btn_flipperNext_nextYear = (ImageButton) nextYear.findViewById(R.id.info_time_nextbtn); btn_flipperNext_nextYear.setVisibility(View.GONE); btn_flipperPrev_nextYear = (ImageButton) nextYear.findViewById(R.id.info_time_prevbtn); btn_flipperPrev_nextYear.setOnClickListener(onPrevCardClick); btn_flipperPrev_nextYear.setOnTouchListener(createButtonListener(btn_flipperPrev_nextYear)); titleNextYear = (TextView) nextYear.findViewById(R.id.text_title); TextView txt_equinox_vernal2_label = (TextView) nextYear .findViewById(R.id.text_date_equinox_vernal_label); TextView txt_equinox_vernal2 = (TextView) nextYear.findViewById(R.id.text_date_equinox_vernal); TextView txt_equinox_vernal2_note = (TextView) nextYear .findViewById(R.id.text_date_equinox_vernal_note); note_equinox_vernal2 = addNote(txt_equinox_vernal2_label, txt_equinox_vernal2, txt_equinox_vernal2_note, 1); TextView txt_solstice_summer2_label = (TextView) nextYear .findViewById(R.id.text_date_solstice_summer_label); TextView txt_solstice_summer2 = (TextView) nextYear.findViewById(R.id.text_date_solstice_summer); TextView txt_solstice_summer2_note = (TextView) nextYear .findViewById(R.id.text_date_solstice_summer_note); note_solstice_summer2 = addNote(txt_solstice_summer2_label, txt_solstice_summer2, txt_solstice_summer2_note, 1); TextView txt_equinox_autumnal2_label = (TextView) nextYear .findViewById(R.id.text_date_equinox_autumnal_label); TextView txt_equinox_autumnal2 = (TextView) nextYear.findViewById(R.id.text_date_equinox_autumnal); TextView txt_equinox_autumnal2_note = (TextView) nextYear .findViewById(R.id.text_date_equinox_autumnal_note); note_equinox_autumnal2 = addNote(txt_equinox_autumnal2_label, txt_equinox_autumnal2, txt_equinox_autumnal2_note, 1); TextView txt_solstice_winter2_label = (TextView) nextYear .findViewById(R.id.text_date_solstice_winter_label); TextView txt_solstice_winter2 = (TextView) nextYear.findViewById(R.id.text_date_solstice_winter); TextView txt_solstice_winter2_note = (TextView) nextYear .findViewById(R.id.text_date_solstice_winter_note); note_solstice_winter2 = addNote(txt_solstice_winter2_label, txt_solstice_winter2, txt_solstice_winter2_note, 1); if (centered) { FrameLayout.LayoutParams lpNextYear = (FrameLayout.LayoutParams) nextYear.getLayoutParams(); lpNextYear.gravity = Gravity.CENTER_HORIZONTAL; nextYear.setLayoutParams(lpNextYear); } } if (isInEditMode()) { updateViews(context, null); } }
From source file:cw.kop.autobackground.sources.SourceListFragment.java
private void startEditFragment(final View view, final int position) { sourceList.setOnItemClickListener(null); sourceList.setEnabled(false);/*from ww w. ja v a 2s. c om*/ listAdapter.saveData(); Source dataItem = listAdapter.getItem(position); final SourceInfoFragment sourceInfoFragment = new SourceInfoFragment(); sourceInfoFragment.setImageDrawable(((ImageView) view.findViewById(R.id.source_image)).getDrawable()); Bundle arguments = new Bundle(); arguments.putInt("position", position); arguments.putString("type", dataItem.getType()); arguments.putString("title", dataItem.getTitle()); arguments.putString("data", dataItem.getData()); arguments.putInt("num", dataItem.getNum()); arguments.putBoolean("use", dataItem.isUse()); arguments.putBoolean("preview", dataItem.isPreview()); String imageFileName = dataItem.getImageFile().getAbsolutePath(); if (imageFileName != null && imageFileName.length() > 0) { arguments.putString("image", imageFileName); } else { arguments.putString("image", ""); } arguments.putBoolean("use_time", dataItem.isUseTime()); arguments.putString("time", dataItem.getTime()); sourceInfoFragment.setArguments(arguments); final RelativeLayout sourceContainer = (RelativeLayout) view.findViewById(R.id.source_container); final CardView sourceCard = (CardView) view.findViewById(R.id.source_card); final View imageOverlay = view.findViewById(R.id.source_image_overlay); final EditText sourceTitle = (EditText) view.findViewById(R.id.source_title); final ImageView deleteButton = (ImageView) view.findViewById(R.id.source_delete_button); final ImageView viewButton = (ImageView) view.findViewById(R.id.source_view_image_button); final ImageView editButton = (ImageView) view.findViewById(R.id.source_edit_button); final LinearLayout sourceExpandContainer = (LinearLayout) view.findViewById(R.id.source_expand_container); final float cardStartShadow = sourceCard.getPaddingLeft(); final float viewStartHeight = sourceContainer.getHeight(); final float viewStartY = view.getY(); final int viewStartPadding = view.getPaddingLeft(); final float textStartX = sourceTitle.getX(); final float textStartY = sourceTitle.getY(); final float textTranslationY = sourceTitle.getHeight(); /*+ TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());*/ Animation animation = new Animation() { private boolean needsFragment = true; @Override protected void applyTransformation(float interpolatedTime, Transformation t) { if (needsFragment && interpolatedTime >= 1) { needsFragment = false; getFragmentManager().beginTransaction() .add(R.id.content_frame, sourceInfoFragment, "source_info_fragment") .addToBackStack(null).setTransition(FragmentTransaction.TRANSIT_NONE).commit(); } int newPadding = Math.round(viewStartPadding * (1 - interpolatedTime)); int newShadowPadding = (int) (cardStartShadow * (1.0f - interpolatedTime)); sourceCard.setShadowPadding(newShadowPadding, 0, newShadowPadding, 0); ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).topMargin = newShadowPadding; ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).bottomMargin = newShadowPadding; ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).leftMargin = newShadowPadding; ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).rightMargin = newShadowPadding; view.setPadding(newPadding, 0, newPadding, 0); view.setY(viewStartY - interpolatedTime * viewStartY); ViewGroup.LayoutParams params = sourceContainer.getLayoutParams(); params.height = (int) (viewStartHeight + (screenHeight - viewStartHeight) * interpolatedTime); sourceContainer.setLayoutParams(params); sourceTitle.setY(textStartY + interpolatedTime * textTranslationY); sourceTitle.setX(textStartX + viewStartPadding - newPadding); deleteButton.setAlpha(1.0f - interpolatedTime); viewButton.setAlpha(1.0f - interpolatedTime); editButton.setAlpha(1.0f - interpolatedTime); sourceExpandContainer.setAlpha(1.0f - interpolatedTime); } @Override public boolean willChangeBounds() { return true; } }; animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { if (needsListReset) { Parcelable state = sourceList.onSaveInstanceState(); sourceList.setAdapter(null); sourceList.setAdapter(listAdapter); sourceList.onRestoreInstanceState(state); sourceList.setOnItemClickListener(SourceListFragment.this); sourceList.setEnabled(true); needsListReset = false; } } @Override public void onAnimationRepeat(Animation animation) { } }); ValueAnimator cardColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), AppSettings.getDialogColor(appContext), getResources().getColor(AppSettings.getBackgroundColorResource())); cardColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { sourceContainer.setBackgroundColor((Integer) animation.getAnimatedValue()); } }); ValueAnimator titleColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), sourceTitle.getCurrentTextColor(), getResources().getColor(R.color.BLUE_OPAQUE)); titleColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { sourceTitle.setTextColor((Integer) animation.getAnimatedValue()); } }); ValueAnimator titleShadowAlphaAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), AppSettings.getColorFilterInt(appContext), getResources().getColor(android.R.color.transparent)); titleShadowAlphaAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { sourceTitle.setShadowLayer(4, 0, 0, (Integer) animation.getAnimatedValue()); } }); ValueAnimator imageOverlayAlphaAnimation = ValueAnimator.ofFloat(imageOverlay.getAlpha(), 0f); imageOverlayAlphaAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { imageOverlay.setAlpha((Float) animation.getAnimatedValue()); } }); int transitionTime = INFO_ANIMATION_TIME; DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(1.5f); animation.setDuration(transitionTime); cardColorAnimation.setDuration(transitionTime); titleColorAnimation.setDuration(transitionTime); titleShadowAlphaAnimation.setDuration(transitionTime); animation.setInterpolator(decelerateInterpolator); cardColorAnimation.setInterpolator(decelerateInterpolator); titleColorAnimation.setInterpolator(decelerateInterpolator); titleShadowAlphaAnimation.setInterpolator(decelerateInterpolator); if (imageOverlay.getAlpha() > 0) { imageOverlayAlphaAnimation.start(); } handler.postDelayed(new Runnable() { @Override public void run() { if (needsListReset) { Parcelable state = sourceList.onSaveInstanceState(); sourceList.setAdapter(null); sourceList.setAdapter(listAdapter); sourceList.onRestoreInstanceState(state); sourceList.setOnItemClickListener(SourceListFragment.this); sourceList.setEnabled(true); needsListReset = false; } } }, (long) (transitionTime * 1.1f)); needsListReset = true; view.startAnimation(animation); cardColorAnimation.start(); titleColorAnimation.start(); titleShadowAlphaAnimation.start(); }
From source file:com.codename1.impl.android.AndroidImplementation.java
@Override public Object showNativePicker(final int type, final Component source, final Object currentValue, final Object data) { if (getActivity() == null) { return null; }/* w ww .j a v a 2 s. c om*/ final boolean[] canceled = new boolean[1]; final boolean[] dismissed = new boolean[1]; if (editInProgress()) { stopEditing(true); } if (type == Display.PICKER_TYPE_TIME) { class TimePick implements TimePickerDialog.OnTimeSetListener, TimePickerDialog.OnCancelListener, Runnable { int result = ((Integer) currentValue).intValue(); public void onTimeSet(TimePicker tp, int hour, int minute) { result = hour * 60 + minute; dismissed[0] = true; synchronized (this) { notify(); } } public void run() { while (!dismissed[0]) { synchronized (this) { try { wait(50); } catch (InterruptedException er) { } } } } @Override public void onCancel(DialogInterface di) { dismissed[0] = true; canceled[0] = true; synchronized (this) { notify(); } } } final TimePick pickInstance = new TimePick(); getActivity().runOnUiThread(new Runnable() { public void run() { int hour = ((Integer) currentValue).intValue() / 60; int minute = ((Integer) currentValue).intValue() % 60; TimePickerDialog tp = new TimePickerDialog(getActivity(), pickInstance, hour, minute, true) { @Override public void cancel() { super.cancel(); dismissed[0] = true; canceled[0] = true; } @Override public void dismiss() { super.dismiss(); dismissed[0] = true; } }; tp.setOnCancelListener(pickInstance); //DateFormat.is24HourFormat(activity)); tp.show(); } }); Display.getInstance().invokeAndBlock(pickInstance); if (canceled[0]) { return null; } return new Integer(pickInstance.result); } if (type == Display.PICKER_TYPE_DATE) { final java.util.Calendar cl = java.util.Calendar.getInstance(); if (currentValue != null) { cl.setTime((Date) currentValue); } class DatePick implements DatePickerDialog.OnDateSetListener, DatePickerDialog.OnCancelListener, Runnable { Date result = (Date) currentValue; public void onDateSet(DatePicker dp, int year, int month, int day) { java.util.Calendar c = java.util.Calendar.getInstance(); c.set(java.util.Calendar.YEAR, year); c.set(java.util.Calendar.MONTH, month); c.set(java.util.Calendar.DAY_OF_MONTH, day); result = c.getTime(); dismissed[0] = true; synchronized (this) { notify(); } } public void run() { while (!dismissed[0]) { synchronized (this) { try { wait(50); } catch (InterruptedException er) { } } } } public void onCancel(DialogInterface di) { result = null; dismissed[0] = true; canceled[0] = true; synchronized (this) { notify(); } } } final DatePick pickInstance = new DatePick(); getActivity().runOnUiThread(new Runnable() { public void run() { DatePickerDialog tp = new DatePickerDialog(getActivity(), pickInstance, cl.get(java.util.Calendar.YEAR), cl.get(java.util.Calendar.MONTH), cl.get(java.util.Calendar.DAY_OF_MONTH)) { @Override public void cancel() { super.cancel(); dismissed[0] = true; canceled[0] = true; } @Override public void dismiss() { super.dismiss(); dismissed[0] = true; } }; tp.setOnCancelListener(pickInstance); tp.show(); } }); Display.getInstance().invokeAndBlock(pickInstance); return pickInstance.result; } if (type == Display.PICKER_TYPE_STRINGS) { final String[] values = (String[]) data; class StringPick implements Runnable, NumberPicker.OnValueChangeListener { int result = -1; StringPick() { } public void run() { while (!dismissed[0]) { synchronized (this) { try { wait(50); } catch (InterruptedException er) { } } } } public void cancel() { dismissed[0] = true; canceled[0] = true; synchronized (this) { notify(); } } public void ok() { canceled[0] = false; dismissed[0] = true; synchronized (this) { notify(); } } @Override public void onValueChange(NumberPicker np, int oldVal, int newVal) { result = newVal; } } final StringPick pickInstance = new StringPick(); for (int iter = 0; iter < values.length; iter++) { if (values[iter].equals(currentValue)) { pickInstance.result = iter; break; } } if (pickInstance.result == -1 && values.length > 0) { // The picker will default to showing the first element anyways // If we don't set the result to 0, then the user has to first // scroll to a different number, then back to the first option // to pick the first option. pickInstance.result = 0; } getActivity().runOnUiThread(new Runnable() { public void run() { NumberPicker picker = new NumberPicker(getActivity()); if (source.getClientProperty("showKeyboard") == null) { picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); } picker.setMinValue(0); picker.setMaxValue(values.length - 1); picker.setDisplayedValues(values); picker.setOnValueChangedListener(pickInstance); if (pickInstance.result > -1) { picker.setValue(pickInstance.result); } RelativeLayout linearLayout = new RelativeLayout(getActivity()); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(50, 50); RelativeLayout.LayoutParams numPicerParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); numPicerParams.addRule(RelativeLayout.CENTER_HORIZONTAL); linearLayout.setLayoutParams(params); linearLayout.addView(picker, numPicerParams); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); alertDialogBuilder.setView(linearLayout); alertDialogBuilder.setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { pickInstance.ok(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); pickInstance.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } }); Display.getInstance().invokeAndBlock(pickInstance); if (canceled[0]) { return null; } if (pickInstance.result < 0) { return null; } return values[pickInstance.result]; } return null; }