List of usage examples for android.widget FrameLayout addView
public void addView(View child)
Adds a child view.
From source file:com.chrslee.csgopedia.app.CardFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //Looks like he did this layout via code this is a layoutparams object //it defines the metrics and bounds of a specific view LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); //Creating a FrameLayout a FrameLayout is basically a empty container FrameLayout fl = new FrameLayout(context); fl.setLayoutParams(params);/*from www. j ava2 s . co m*/ //setting the params from above // First - image section //Building the imageview via code LayoutParams imgParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); imgParams.gravity = Gravity.CENTER; //setting all centered ImageView iv = new ImageView(context); iv.setLayoutParams(imgParams); iv.setScaleType(ImageView.ScaleType.CENTER_INSIDE); iv.setAdjustViewBounds(true); iv.setBackgroundResource(getActivity().getIntent().getExtras().getInt("iconID")); //seting the iconID as the image of this imageView // Second - prices section //final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources() // .getDisplayMetrics()); // //LinearLayout is another container it just take the //widgets inside it and display them in a linear order LinearLayout linLayout = new LinearLayout(context); linLayout.setOrientation(LinearLayout.VERTICAL); linLayout.setLayoutParams(params); linLayout.setGravity(Gravity.CENTER); // Get prices ConnectionDetector cd = new ConnectionDetector(context); //creating a connection detector to check for internet String query = getActivity().getIntent().getStringExtra("searchQuery"); //taking the name or whatever he pass from mainactivity from the searchquery arg TextView placeholder = new TextView(context); ///this is a textview for the name of the item if (cd.isConnectedToInternet()) {//if its connected to internet then if (query.equals("-1")) {//if the skin is regular he display is not for sale placeholder.setText("Regular skins are not for sale!"); linLayout.addView(placeholder); } else {//else he calls the scrappperAsyncTask with the query new ScraperAsyncTask(linLayout).execute(query); } } else {//if its not connected he display the message here placeholder.setText("Please connect to the Internet to view prices."); linLayout.addView(placeholder); } //here he defines which tab he is displaying, Now I see why he used the same fragment, //this is a bad practice, he created both widgets before but just displays one of them //for each case if its the first tab he display the image if its the second the prices if (position == 0) { fl.addView(iv); } else { fl.addView(linLayout); } //Then he returns the framelayout (container) to display it in the screen return fl; }
From source file:org.telegram.ui.SessionsActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(LocaleController.getString("SessionsTitle", R.string.SessionsTitle)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override// ww w . j a va 2 s . c o m public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); listAdapter = new ListAdapter(context); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); emptyLayout = new LinearLayout(context); emptyLayout.setOrientation(LinearLayout.VERTICAL); emptyLayout.setGravity(Gravity.CENTER); //emptyLayout.setBackgroundResource(R.drawable.greydivider_bottom); emptyLayout.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight())); ImageView imageView = new ImageView(context); imageView.setImageResource(R.drawable.devices); emptyLayout.addView(imageView); LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) imageView.getLayoutParams(); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; imageView.setLayoutParams(layoutParams2); TextView textView = new TextView(context); textView.setTextColor(ContextCompat.getColor(context, R.color.disabled_text) /*0xff8a8a8a*/); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17); textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); textView.setText(LocaleController.getString("NoOtherSessions", R.string.NoOtherSessions)); emptyLayout.addView(textView); layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams2.topMargin = AndroidUtilities.dp(16); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; layoutParams2.gravity = Gravity.CENTER; textView.setLayoutParams(layoutParams2); textView = new TextView(context); textView.setTextColor(ContextCompat.getColor(context, R.color.disabled_text) /*0xff8a8a8a*/); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17); textView.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0); textView.setText(LocaleController.getString("NoOtherSessionsInfo", R.string.NoOtherSessionsInfo)); emptyLayout.addView(textView); layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams2.topMargin = AndroidUtilities.dp(14); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; layoutParams2.gravity = Gravity.CENTER; textView.setLayoutParams(layoutParams2); FrameLayout progressView = new FrameLayout(context); frameLayout.addView(progressView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; progressView.setLayoutParams(layoutParams); progressView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); ProgressBar progressBar = new ProgressBar(context); progressView.addView(progressBar); layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.gravity = Gravity.CENTER; progressView.setLayoutParams(layoutParams); ListView listView = new ListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); listView.setDrawSelectorOnTop(true); listView.setEmptyView(progressView); frameLayout.addView(listView); layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP; listView.setLayoutParams(layoutParams); listView.setAdapter(listAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) { if (i == terminateAllSessionsRow) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage( LocaleController.getString("AreYouSureSessions", R.string.AreYouSureSessions)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { TLRPC.TL_auth_resetAuthorizations req = new TLRPC.TL_auth_resetAuthorizations(); ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { if (getParentActivity() == null) { return; } if (error == null && response instanceof TLRPC.TL_boolTrue) { Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("TerminateAllSessions", R.string.TerminateAllSessions), Toast.LENGTH_SHORT); toast.show(); } else { Toast toast = Toast .makeText(getParentActivity(), LocaleController.getString("UnknownError", R.string.UnknownError), Toast.LENGTH_SHORT); toast.show(); } finishFragment(); } }); UserConfig.registeredForPush = false; UserConfig.saveConfig(false); MessagesController.getInstance().registerForPush(UserConfig.pushString); ConnectionsManager.getInstance() .setUserId(UserConfig.getClientUserId()); } }); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i >= otherSessionsStartRow && i < otherSessionsEndRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("TerminateSessionQuestion", R.string.TerminateSessionQuestion)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int option) { final ProgressDialog progressDialog = new ProgressDialog(getParentActivity()); progressDialog .setMessage(LocaleController.getString("Loading", R.string.Loading)); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCancelable(false); progressDialog.show(); final TLRPC.TL_authorization authorization = sessions .get(i - otherSessionsStartRow); TLRPC.TL_account_resetAuthorization req = new TLRPC.TL_account_resetAuthorization(); req.hash = authorization.hash; ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { try { progressDialog.dismiss(); } catch (Exception e) { FileLog.e("tmessages", e); } if (error == null) { sessions.remove(authorization); updateRows(); if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } } } }); } }); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } } }); return fragmentView; }
From source file:com.ichi2.anki2.Reviewer.java
private void initLayout(Integer layout) { setContentView(layout);//from w ww. ja va2 s . co m mMainLayout = findViewById(R.id.main_layout); Themes.setContentStyle(mMainLayout, Themes.CALLER_REVIEWER); mCardContainer = (FrameLayout) findViewById(R.id.flashcard_frame); setInAnimation(false); findViewById(R.id.top_bar).setOnClickListener(mCardStatisticsListener); mCardFrame = (FrameLayout) findViewById(R.id.flashcard); mTouchLayer = (FrameLayout) findViewById(R.id.touch_layer); mTouchLayer.setOnTouchListener(mGestureListener); if (mPrefTextSelection && mLongClickWorkaround) { mTouchLayer.setOnLongClickListener(mLongClickListener); } if (mPrefTextSelection) { mClipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); } mCardFrame.removeAllViews(); if (!mChangeBorderStyle) { ((View) findViewById(R.id.flashcard_border)).setVisibility(View.VISIBLE); } // hunt for input issue 720, like android issue 3341 if (AnkiDroidApp.SDK_VERSION <= 7 && (mCard != null)) { mCard.setFocusableInTouchMode(true); } // Initialize swipe gestureDetector = new GestureDetector(new MyGestureDetector()); mProgressBar = (ProgressBar) findViewById(R.id.flashcard_progressbar); // initialise shake detection if (mShakeEnabled) { mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mSensorManager.registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); mAccel = 0.00f; mAccelCurrent = SensorManager.GRAVITY_EARTH; mAccelLast = SensorManager.GRAVITY_EARTH; } Resources res = getResources(); mEase1 = (Button) findViewById(R.id.ease1); mEase1.setTextColor(res.getColor(R.color.next_time_failed_color)); mEase1Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease1); mEase1Layout.setOnClickListener(mSelectEaseHandler); mEase2 = (Button) findViewById(R.id.ease2); mEase2.setTextColor(res.getColor(R.color.next_time_usual_color)); mEase2Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease2); mEase2Layout.setOnClickListener(mSelectEaseHandler); mEase3 = (Button) findViewById(R.id.ease3); mEase3Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease3); mEase3Layout.setOnClickListener(mSelectEaseHandler); mEase4 = (Button) findViewById(R.id.ease4); mEase4Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease4); mEase4Layout.setOnClickListener(mSelectEaseHandler); mNext1 = (TextView) findViewById(R.id.nextTime1); mNext2 = (TextView) findViewById(R.id.nextTime2); mNext3 = (TextView) findViewById(R.id.nextTime3); mNext4 = (TextView) findViewById(R.id.nextTime4); mNext1.setTextColor(res.getColor(R.color.next_time_failed_color)); mNext2.setTextColor(res.getColor(R.color.next_time_usual_color)); if (!mshowNextReviewTime) { ((TextView) findViewById(R.id.nextTimeflip)).setVisibility(View.GONE); mNext1.setVisibility(View.GONE); mNext2.setVisibility(View.GONE); mNext3.setVisibility(View.GONE); mNext4.setVisibility(View.GONE); } mFlipCard = (Button) findViewById(R.id.flip_card); mFlipCardLayout = (LinearLayout) findViewById(R.id.flashcard_layout_flip); mFlipCardLayout.setOnClickListener(mFlipCardListener); mTextBarRed = (TextView) findViewById(R.id.red_number); mTextBarBlack = (TextView) findViewById(R.id.black_number); mTextBarBlue = (TextView) findViewById(R.id.blue_number); if (mShowProgressBars) { mSessionProgressTotalBar = (View) findViewById(R.id.daily_bar); mSessionProgressBar = (View) findViewById(R.id.session_progress); mProgressBars = (LinearLayout) findViewById(R.id.progress_bars); } mCardTimer = (Chronometer) findViewById(R.id.card_time); if (mShowProgressBars && mProgressBars.getVisibility() != View.VISIBLE) { switchVisibility(mProgressBars, View.VISIBLE); } mChosenAnswer = (TextView) findViewById(R.id.choosen_answer); if (mPrefWhiteboard) { mWhiteboard = new Whiteboard(this, mInvertedColors, mBlackWhiteboard); FrameLayout.LayoutParams lp2 = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); mWhiteboard.setLayoutParams(lp2); FrameLayout fl = (FrameLayout) findViewById(R.id.whiteboard); fl.addView(mWhiteboard); mWhiteboard.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (mShowWhiteboard) { return false; } if (gestureDetector.onTouchEvent(event)) { return true; } return false; } }); } mAnswerField = (EditText) findViewById(R.id.answer_field); mNextTimeTextColor = getResources().getColor(R.color.next_time_usual_color); mNextTimeTextRecomColor = getResources().getColor(R.color.next_time_recommended_color); mForegroundColor = getResources().getColor(R.color.next_time_usual_color); if (mInvertedColors) { invertColors(true); } mLookUpIcon = findViewById(R.id.lookup_button); mLookUpIcon.setVisibility(View.GONE); mLookUpIcon.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (clipboardHasText()) { lookUp(); } } }); initControls(); }
From source file:com.nit.vicky.Reviewer.java
private void initLayout(Integer layout) { setContentView(layout);/* w w w. j ava 2 s . c o m*/ mMainLayout = findViewById(R.id.main_layout); Themes.setContentStyle(mMainLayout, Themes.CALLER_REVIEWER); mCardContainer = (FrameLayout) findViewById(R.id.flashcard_frame); setInAnimation(false); findViewById(R.id.top_bar).setOnClickListener(mCardStatisticsListener); mCardFrame = (FrameLayout) findViewById(R.id.flashcard); mTouchLayer = (FrameLayout) findViewById(R.id.touch_layer); mTouchLayer.setOnTouchListener(mGestureListener); if (mPrefTextSelection && mLongClickWorkaround) { mTouchLayer.setOnLongClickListener(mLongClickListener); } if (mPrefTextSelection) { mClipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); } mCardFrame.removeAllViews(); if (!mChangeBorderStyle) { ((View) findViewById(R.id.flashcard_border)).setVisibility(View.VISIBLE); } // hunt for input issue 720, like android issue 3341 if (AnkiDroidApp.SDK_VERSION <= 7 && (mCard != null)) { mCard.setFocusableInTouchMode(true); } // Initialize swipe gestureDetector = new GestureDetector(new MyGestureDetector()); mProgressBar = (ProgressBar) findViewById(R.id.flashcard_progressbar); // initialise shake detection if (mShakeEnabled) { mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mSensorManager.registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); mAccel = 0.00f; mAccelCurrent = SensorManager.GRAVITY_EARTH; mAccelLast = SensorManager.GRAVITY_EARTH; } Resources res = getResources(); mEase1 = (Button) findViewById(R.id.ease1); mEase1.setTextColor(res.getColor(R.color.next_time_failed_color)); mEase1Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease1); mEase1Layout.setOnClickListener(mSelectEaseHandler); mEase2 = (Button) findViewById(R.id.ease2); mEase2.setTextColor(res.getColor(R.color.next_time_usual_color)); mEase2Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease2); mEase2Layout.setOnClickListener(mSelectEaseHandler); mEase3 = (Button) findViewById(R.id.ease3); mEase3Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease3); mEase3Layout.setOnClickListener(mSelectEaseHandler); mEase4 = (Button) findViewById(R.id.ease4); mEase4Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease4); mEase4Layout.setOnClickListener(mSelectEaseHandler); mNext1 = (TextView) findViewById(R.id.nextTime1); mNext2 = (TextView) findViewById(R.id.nextTime2); mNext3 = (TextView) findViewById(R.id.nextTime3); mNext4 = (TextView) findViewById(R.id.nextTime4); mNext1.setTextColor(res.getColor(R.color.next_time_failed_color)); mNext2.setTextColor(res.getColor(R.color.next_time_usual_color)); if (!mShowNextReviewTime) { ((TextView) findViewById(R.id.nextTimeflip)).setVisibility(View.GONE); mNext1.setVisibility(View.GONE); mNext2.setVisibility(View.GONE); mNext3.setVisibility(View.GONE); mNext4.setVisibility(View.GONE); } mFlipCard = (Button) findViewById(R.id.flip_card); mFlipCardLayout = (LinearLayout) findViewById(R.id.flashcard_layout_flip); mFlipCardLayout.setOnClickListener(mFlipCardListener); mTextBarRed = (TextView) findViewById(R.id.red_number); mTextBarBlack = (TextView) findViewById(R.id.black_number); mTextBarBlue = (TextView) findViewById(R.id.blue_number); if (!mShowRemainingCardCount) { mTextBarRed.setVisibility(View.GONE); mTextBarBlack.setVisibility(View.GONE); mTextBarBlue.setVisibility(View.GONE); } if (mShowProgressBars) { mSessionProgressTotalBar = (View) findViewById(R.id.daily_bar); mSessionProgressBar = (View) findViewById(R.id.session_progress); mProgressBars = (LinearLayout) findViewById(R.id.progress_bars); } mCardTimer = (Chronometer) findViewById(R.id.card_time); if (mShowProgressBars && mProgressBars.getVisibility() != View.VISIBLE) { switchVisibility(mProgressBars, View.VISIBLE); } mChosenAnswer = (TextView) findViewById(R.id.choosen_answer); if (mPrefWhiteboard) { mWhiteboard = new Whiteboard(this, mInvertedColors, mBlackWhiteboard); FrameLayout.LayoutParams lp2 = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); mWhiteboard.setLayoutParams(lp2); FrameLayout fl = (FrameLayout) findViewById(R.id.whiteboard); fl.addView(mWhiteboard); mWhiteboard.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (mShowWhiteboard) { return false; } if (gestureDetector.onTouchEvent(event)) { return true; } return false; } }); } mAnswerField = (EditText) findViewById(R.id.answer_field); mNextTimeTextColor = getResources().getColor(R.color.next_time_usual_color); mNextTimeTextRecomColor = getResources().getColor(R.color.next_time_recommended_color); mForegroundColor = getResources().getColor(R.color.next_time_usual_color); if (mInvertedColors) { invertColors(true); } mLookUpIcon = findViewById(R.id.lookup_button); mLookUpIcon.setVisibility(View.GONE); mLookUpIcon.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (clipboardHasText()) { lookUp(); } } }); initControls(); }
From source file:com.hichinaschool.flashcards.anki.Reviewer.java
private void initLayout(Integer layout) { setContentView(layout);/* ww w . j ava2s. com*/ mMainLayout = findViewById(R.id.main_layout); Themes.setContentStyle(mMainLayout, Themes.CALLER_REVIEWER); mCardContainer = (FrameLayout) findViewById(R.id.flashcard_frame); setInAnimation(false); findViewById(R.id.top_bar).setOnClickListener(mCardStatisticsListener); mCardFrame = (FrameLayout) findViewById(R.id.flashcard); mTouchLayer = (FrameLayout) findViewById(R.id.touch_layer); mTouchLayer.setOnTouchListener(mGestureListener); if (mPrefTextSelection && mLongClickWorkaround) { mTouchLayer.setOnLongClickListener(mLongClickListener); } if (mPrefTextSelection) { mClipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); } mCardFrame.removeAllViews(); if (!mChangeBorderStyle) { ((View) findViewById(R.id.flashcard_border)).setVisibility(View.VISIBLE); } // hunt for input issue 720, like android issue 3341 if (AnkiDroidApp.SDK_VERSION <= 7 && (mCard != null)) { mCard.setFocusableInTouchMode(true); } // Initialize swipe gestureDetector = new GestureDetector(new MyGestureDetector()); mProgressBar = (ProgressBar) findViewById(R.id.flashcard_progressbar); // initialise shake detection if (mShakeEnabled) { mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mSensorManager.registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); mAccel = 0.00f; mAccelCurrent = SensorManager.GRAVITY_EARTH; mAccelLast = SensorManager.GRAVITY_EARTH; } Resources res = getResources(); mEase1 = (Button) findViewById(R.id.ease1); mEase1.setTextColor(res.getColor(R.color.next_time_failed_color)); mEase1Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease1); mEase1Layout.setOnClickListener(mSelectEaseHandler); mEase2 = (Button) findViewById(R.id.ease2); mEase2.setTextColor(res.getColor(R.color.next_time_usual_color)); mEase2Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease2); mEase2Layout.setOnClickListener(mSelectEaseHandler); mEase3 = (Button) findViewById(R.id.ease3); mEase3Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease3); mEase3Layout.setOnClickListener(mSelectEaseHandler); mEase4 = (Button) findViewById(R.id.ease4); mEase4Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease4); mEase4Layout.setOnClickListener(mSelectEaseHandler); mNext1 = (TextView) findViewById(R.id.nextTime1); mNext2 = (TextView) findViewById(R.id.nextTime2); mNext3 = (TextView) findViewById(R.id.nextTime3); mNext4 = (TextView) findViewById(R.id.nextTime4); mNext1.setTextColor(res.getColor(R.color.next_time_failed_color)); mNext2.setTextColor(res.getColor(R.color.next_time_usual_color)); if (!mShowNextReviewTime) { ((TextView) findViewById(R.id.nextTimeflip)).setVisibility(View.GONE); mNext1.setVisibility(View.GONE); mNext2.setVisibility(View.GONE); mNext3.setVisibility(View.GONE); mNext4.setVisibility(View.GONE); } mFlipCard = (Button) findViewById(R.id.flip_card); mFlipCardLayout = (LinearLayout) findViewById(R.id.flashcard_layout_flip); mFlipCardLayout.setOnClickListener(mFlipCardListener); mTextBarRed = (TextView) findViewById(R.id.red_number); mTextBarBlack = (TextView) findViewById(R.id.black_number); mTextBarBlue = (TextView) findViewById(R.id.blue_number); if (!mShowRemainingCardCount) { mTextBarRed.setVisibility(View.GONE); mTextBarBlack.setVisibility(View.GONE); mTextBarBlue.setVisibility(View.GONE); } if (mShowProgressBars) { mSessionProgressTotalBar = (View) findViewById(R.id.daily_bar); mSessionProgressBar = (View) findViewById(R.id.session_progress); mProgressBars = (LinearLayout) findViewById(R.id.progress_bars); } mCardTimer = (Chronometer) findViewById(R.id.card_time); if (mShowProgressBars && mProgressBars.getVisibility() != View.VISIBLE) { // switchVisibility(mProgressBars, View.VISIBLE); } mChosenAnswer = (TextView) findViewById(R.id.choosen_answer); if (mPrefWhiteboard) { mWhiteboard = new Whiteboard(this, mInvertedColors, mBlackWhiteboard); FrameLayout.LayoutParams lp2 = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); mWhiteboard.setLayoutParams(lp2); FrameLayout fl = (FrameLayout) findViewById(R.id.whiteboard); fl.addView(mWhiteboard); mWhiteboard.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (mShowWhiteboard) { return false; } if (gestureDetector.onTouchEvent(event)) { return true; } return false; } }); } mAnswerField = (EditText) findViewById(R.id.answer_field); mNextTimeTextColor = getResources().getColor(R.color.next_time_usual_color); mNextTimeTextRecomColor = getResources().getColor(R.color.next_time_recommended_color); mForegroundColor = getResources().getColor(R.color.next_time_usual_color); if (mInvertedColors) { invertColors(true); } mLookUpIcon = findViewById(R.id.lookup_button); mLookUpIcon.setVisibility(View.GONE); mLookUpIcon.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (clipboardHasText()) { lookUp(); } } }); initControls(); }
From source file:com.google.android.gcm.demo.ui.NetworkSchedulerFragment.java
@Override public void refresh() { FrameLayout tasksView = (FrameLayout) getActivity().findViewById(R.id.scheduler_tasks); // the view might have been destroyed, in which case we don't do anything if (tasksView != null) { float density = getActivity().getResources().getDisplayMetrics().density; SimpleArrayMap<String, TaskTracker> tasks = mTasks.getTasks(); LinearLayout tasksList = new LinearLayout(getActivity()); tasksList.setOrientation(LinearLayout.VERTICAL); for (int i = 0; i < tasks.size(); i++) { final TaskTracker task = tasks.valueAt(i); CardView taskCard = (CardView) getActivity().getLayoutInflater().inflate(R.layout.widget_task, tasksList, false);/*from w w w . jav a 2 s . c o m*/ ImageView taskIcon = (ImageView) taskCard.findViewById(R.id.task_icon); taskIcon.setImageResource(R.drawable.check_circle_grey600); taskIcon.setPadding(0, 0, (int) (8 * density), 0); TextView taskLabel = (TextView) taskCard.findViewById(R.id.task_title); TextView taskParams = (TextView) taskCard.findViewById(R.id.task_params); if (task.period == 0) { taskLabel.setText(getString(R.string.scheduler_oneoff, task.tag)); taskParams.setText(getString(R.string.scheduler_oneoff_params, task.windowStartElapsedSecs, task.windowStopElapsedSecs)); } else { taskLabel.setText(getString(R.string.scheduler_periodic, task.tag)); taskParams.setText(getString(R.string.scheduler_periodic_params, task.period, task.flex)); } TextView taskCreatedAt = (TextView) taskCard.findViewById(R.id.task_created_at); taskCreatedAt.setText(getString(R.string.scheduler_secs_ago, DateUtils .formatElapsedTime(SystemClock.elapsedRealtime() / 1000 - task.createdAtElapsedSecs))); TextView lastExecuted = (TextView) taskCard.findViewById(R.id.task_last_exec); if (task.executionTimes.isEmpty()) { lastExecuted.setText(getString(R.string.scheduler_na)); } else { long lastExecTime = task.executionTimes.get(task.executionTimes.size() - 1); lastExecuted.setText(getString(R.string.scheduler_secs_ago, DateUtils.formatElapsedTime(SystemClock.elapsedRealtime() / 1000 - lastExecTime))); } TextView state = (TextView) taskCard.findViewById(R.id.task_state); if (task.isCancelled()) { state.setText(getString(R.string.scheduler_cancelled)); } else if (task.isExecuted()) { state.setText(getString(R.string.scheduler_executed)); } else { state.setText(getString(R.string.scheduler_pending)); } Button cancel = (Button) taskCard.findViewById(R.id.task_cancel); cancel.setVisibility(View.VISIBLE); cancel.setText(R.string.scheduler_cancel); Button delete = (Button) taskCard.findViewById(R.id.task_delete); delete.setVisibility(View.VISIBLE); delete.setText(R.string.scheduler_delete); if (!task.isCancelled() && (!task.isExecuted() || task.period != 0)) { cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { cancelTask(task.tag); refresh(); } }); cancel.setEnabled(true); delete.setEnabled(false); } else { cancel.setEnabled(false); delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mTasks.deleteTask(task.tag); refresh(); } }); delete.setEnabled(true); } tasksList.addView(taskCard); } tasksView.removeAllViews(); tasksView.addView(tasksList); } }
From source file:org.shaastra.helper.SuperAwesomeCardFragment.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override/*from ww w . j a va2s .co m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); FrameLayout fl = new FrameLayout(getActivity()); fl.setLayoutParams(params); final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()); TextView v = new TextView(getActivity()); params.setMargins(margin, margin, margin, margin); v.setLayoutParams(params); v.setLayoutParams(params); v.setGravity(Gravity.CENTER); //v.setBackgroundResource(R.drawable.background_card); v.setText("CARD " + (position + 1)); if (position == 0) { View v1 = inflater.inflate(R.layout.event_info, container, false); v1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); TextView t1 = (TextView) v1.findViewById(R.id.infotext); t1.setText(eintroduction); return v1; } else if (position == 1) { String Venue = new String(); Venue = evenue; final String SAC = elatlong; //String start=String.valueOf(l.getLatitude())+String.valueOf(l.getLongitude()); /* View v1=inflater.inflate(R.layout.map, container,false); v1.setLayoutParams(params); WebView wv=(WebView)v1.findViewById(R.id.wv1); wv.setWebChromeClient(new WebChromeClient()); //wv.loadUrl("https://maps.google.com/maps?saddr=13,80&daddr=13,80.02"); //wv.loadUrl("http://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&sensor=false"); wv.loadUrl("http://maps.google.com/maps?f=d&daddr=51.448,-0.972"); wv.getSettings().getBuiltInZoomControls(); */ View v1 = inflater.inflate(R.layout.map, container, false); v1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); TextView location = (TextView) v1.findViewById(R.id.locationText); Button mapButton = (Button) v1.findViewById(R.id.mapButton); if (evenue.equalsIgnoreCase("NONE")) { mapButton.setAlpha(0); } else { mapButton.setAlpha(1); } location.setText(Venue); mapButton.setOnTouchListener(new View.OnTouchListener() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) @SuppressLint("NewApi") @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub if (event.getAction() == MotionEvent.ACTION_DOWN) { v.setAlpha((float) 0.4); v.animate().setInterpolator(new DecelerateInterpolator()).scaleX(0.9f).scaleY(0.9f); } if (event.getAction() == MotionEvent.ACTION_UP) { v.setAlpha((float) 0.75); v.animate().setInterpolator(new OvershootInterpolator()).scaleX(1f).scaleY(1f); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?f=d&daddr=" + SAC)); intent.setComponent(new ComponentName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity")); startActivity(intent); } return false; } }); return v1; } else if (position == 2) { View v1 = inflater.inflate(R.layout.event_info, container, false); v1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); TextView t1 = (TextView) v1.findViewById(R.id.infotext); t1.setText(eformat); return v1; } else if (position == 3) { View v1 = inflater.inflate(R.layout.prize, container, false); v1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); TextView t1 = (TextView) v1.findViewById(R.id.prizeText); t1.setText(eprize); return v1; } else if (position == 4) { v.setBackgroundColor(Color.GREEN); } else if (position == 5) { v.setBackgroundColor(Color.MAGENTA); } else if (position == 6) { v.setBackgroundColor(Color.MAGENTA); } fl.addView(v); return fl; }
From source file:com.example.diplimadoapp.SuperAwesomeCardFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); FrameLayout fl = new FrameLayout(getActivity()); fl.setLayoutParams(params);/* w w w .ja v a 2 s.c o m*/ final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()); switch (position) { case 0: LinearLayout ll = new LinearLayout(getActivity()); ll.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); ll.setOrientation(LinearLayout.VERTICAL); ImageView iv = new ImageView(getActivity()); iv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 1020)); //iv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT)); iv.setMaxHeight(520); iv.setImageResource(R.drawable.contact); ll.addView(iv); TableLayout tl = new TableLayout(getActivity()); tl.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); TableRow tr = new TableRow(getActivity()); tr.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); tr.setGravity(Gravity.FILL_HORIZONTAL); tr.setPadding(5, 5, 5, 5); List<RssItem> lecturaitems = null; try { // Create RSS reader RssReader rssReader = new RssReader( "http://www.senalradionica.gov.co/index.php/home/articulos/itemlist?format=feed"); // Get a ListView from main view //ListView itcItems = (ListView) findViewById(R.id.listMainView); lecturaitems = rssReader.getItems(); } catch (Exception e) { Log.e("Diplomado App Reader", e.getMessage()); } TextView v1 = new TextView(getActivity()); params.setMargins(margin, margin, margin, margin); v1.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2)); v1.setGravity(Gravity.CENTER); v1.setBackgroundResource(R.drawable.background_card); if (lecturaitems != null) { v1.setText(lecturaitems.get(0).getTitle()); String urlnoticia = lecturaitems.get(0).getLink(); v1.setOnClickListener(new NoticiaDestacadaOnClickListener(urlnoticia)); } else { v1.setText("No Registra nuevas noticias"); } tr.addView(v1); ImageButton ib = new ImageButton(getActivity()); ib.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1)); ib.setImageResource(R.drawable.facebook); ib.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW); myWebLink.setData(Uri.parse("http://www.facebook.com")); startActivity(myWebLink); } }); tr.addView(ib); ImageButton ib2 = new ImageButton(getActivity()); ib2.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1)); ib2.setImageResource(R.drawable.twitter); ib2.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW); myWebLink.setData(Uri.parse("http://www.twitter.com")); startActivity(myWebLink); } }); tr.addView(ib2); ImageButton ib3 = new ImageButton(getActivity()); ib3.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1)); ib3.setImageResource(R.drawable.youtube); ib3.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW); myWebLink.setData(Uri.parse("http://www.youtube.com")); startActivity(myWebLink); } }); tr.addView(ib3); tl.addView(tr); ll.addView(tl); fl.addView(ll); break; case 1: LinearLayout ll2 = new LinearLayout(getActivity()); ll2.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); ll2.setOrientation(LinearLayout.VERTICAL); TableLayout tl2 = new TableLayout(getActivity()); tl2.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); TableRow tr2 = new TableRow(getActivity()); tr2.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); tr2.setGravity(Gravity.FILL_HORIZONTAL); tr2.setPadding(5, 5, 5, 5); TextView v0 = new TextView(getActivity()); params.setMargins(margin, margin, margin, margin); v0.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2)); v0.setGravity(Gravity.CENTER); v0.setText("Acusticos Radionoca. Lunes a Viernes 8:00 a.m. - 9:00 a.m."); tr2.addView(v0); ImageButton ib20 = new ImageButton(getActivity()); ib20.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1)); ib20.setImageResource(R.drawable.pacusticos); ib20.setBackgroundDrawable(null); tr2.addView(ib20); tl2.addView(tr2); TableRow tr3 = new TableRow(getActivity()); tr3.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); tr3.setGravity(Gravity.FILL_HORIZONTAL); tr3.setPadding(5, 5, 5, 5); TextView v03 = new TextView(getActivity()); params.setMargins(margin, margin, margin, margin); v03.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2)); v03.setGravity(Gravity.CENTER); v03.setText("Acusticos Radionoca. Lunes a Viernes 8:00 a.m. - 9:00 a.m."); tr3.addView(v03); ImageButton ib30 = new ImageButton(getActivity()); ib30.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1)); ib30.setImageResource(R.drawable.pradionica_lacarta); ib30.setBackgroundDrawable(null); tr3.addView(ib30); tl2.addView(tr3); TableRow tr4 = new TableRow(getActivity()); tr4.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); tr4.setGravity(Gravity.FILL_HORIZONTAL); tr4.setPadding(5, 5, 5, 5); TextView v04 = new TextView(getActivity()); params.setMargins(margin, margin, margin, margin); v04.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2)); v04.setGravity(Gravity.CENTER); v04.setText("Acusticos Radionoca. Lunes a Viernes 8:00 a.m. - 9:00 a.m."); tr4.addView(v04); tl2.addView(tr4); ImageButton ib40 = new ImageButton(getActivity()); ib40.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1)); ib40.setImageResource(R.drawable.prockeros); ib40.setBackgroundDrawable(null); tr4.addView(ib40); ll2.addView(tl2); /* VideoView videoView = new VideoView(getActivity()); Uri path = Uri.parse("rtmp://cdns840stu0010.multistream.net:80/rtvcRadionicalive/?pass=|radionica|"); videoView.setVideoURI(path); videoView.start(); TableRow tr5 =new TableRow(getActivity()); tr5.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); tr5.setGravity(Gravity.FILL_HORIZONTAL); tr5.setPadding(5,5,5,5); tr5.addView(videoView); ll2.addView(tr5);*/ fl.addView(ll2); break; case 2: ListView lv = new ListView(getActivity()); params.setMargins(margin, margin, margin, margin); lv.setLayoutParams(params); lv.setLayoutParams(params); lv.setBackgroundResource(R.drawable.background_card); try { // Create RSS reader RssReader rssReader = new RssReader( "http://www.senalradionica.gov.co/index.php/home/articulos/itemlist?format=feed"); // Get a ListView from main view //ListView itcItems = (ListView) findViewById(R.id.listMainView); List<RssItem> lecturaitems2 = rssReader.getItems(); // Create a list adapter ArrayAdapter<RssItem> adapter = new ArrayAdapter<RssItem>(getActivity(), android.R.layout.simple_list_item_1, lecturaitems2); // Set list adapter for the ListView lv.setAdapter(adapter); // Set list view item click listener lv.setOnItemClickListener(new ListListener(lecturaitems2, getActivity())); } catch (Exception e) { Log.e("Diplomado App Reader", e.getMessage()); } fl.addView(lv); break; } return fl; }
From source file:com.stoutner.privacybrowser.MainWebViewActivity.java
@Override // Remove Android Studio's warning about the dangers of using SetJavaScriptEnabled. The whole premise of Privacy Browser is built around an understanding of these dangers. @SuppressLint("SetJavaScriptEnabled") protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_coordinatorlayout); // We need to use the SupportActionBar from android.support.v7.app.ActionBar until the minimum API is >= 21. Toolbar supportAppBar = (Toolbar) findViewById(R.id.appBar); setSupportActionBar(supportAppBar);//from ww w .j av a 2 s .c om final ActionBar appBar = getSupportActionBar(); // This is needed to get rid of the Android Studio warning that appBar might be null. assert appBar != null; // Add the custom url_bar layout, which shows the favoriteIcon, urlTextBar, and progressBar. appBar.setCustomView(R.layout.url_bar); appBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); // Set the "go" button on the keyboard to load the URL in urlTextBox. urlTextBox = (EditText) appBar.getCustomView().findViewById(R.id.urlTextBox); urlTextBox.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button, load the URL. if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Load the URL into the mainWebView and consume the event. try { loadUrlFromTextBox(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } // If the enter key was pressed, consume the event. return true; } else { // If any other key was pressed, do not consume the event. return false; } } }); final FrameLayout fullScreenVideoFrameLayout = (FrameLayout) findViewById(R.id.fullScreenVideoFrameLayout); // Implement swipe to refresh swipeToRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout); assert swipeToRefresh != null; //This assert removes the incorrect warning on the following line that swipeToRefresh might be null. swipeToRefresh.setColorSchemeResources(R.color.blue); swipeToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mainWebView.reload(); } }); mainWebView = (WebView) findViewById(R.id.mainWebView); // Create the navigation drawer. drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout); // The DrawerTitle identifies the drawer in accessibility mode. drawerLayout.setDrawerTitle(GravityCompat.START, getString(R.string.navigation_drawer)); // Listen for touches on the navigation menu. final NavigationView navigationView = (NavigationView) findViewById(R.id.navigationView); assert navigationView != null; // This assert removes the incorrect warning on the following line that navigationView might be null. navigationView.setNavigationItemSelectedListener(this); // drawerToggle creates the hamburger icon at the start of the AppBar. drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, supportAppBar, R.string.open_navigation, R.string.close_navigation); mainWebView.setWebViewClient(new WebViewClient() { // shouldOverrideUrlLoading makes this WebView the default handler for URLs inside the app, so that links are not kicked out to other apps. @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { mainWebView.loadUrl(url); return true; } // Update the URL in urlTextBox when the page starts to load. @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { urlTextBox.setText(url); } // Update formattedUrlString and urlTextBox. It is necessary to do this after the page finishes loading because the final URL can change during load. @Override public void onPageFinished(WebView view, String url) { formattedUrlString = url; // Only update urlTextBox if the user is not typing in it. if (!urlTextBox.hasFocus()) { urlTextBox.setText(formattedUrlString); } } }); mainWebView.setWebChromeClient(new WebChromeClient() { // Update the progress bar when a page is loading. @Override public void onProgressChanged(WebView view, int progress) { // Make sure that appBar is not null. if (appBar != null) { ProgressBar progressBar = (ProgressBar) appBar.getCustomView().findViewById(R.id.progressBar); progressBar.setProgress(progress); if (progress < 100) { progressBar.setVisibility(View.VISIBLE); } else { progressBar.setVisibility(View.GONE); //Stop the SwipeToRefresh indicator if it is running swipeToRefresh.setRefreshing(false); } } } // Set the favorite icon when it changes. @Override public void onReceivedIcon(WebView view, Bitmap icon) { // Save a copy of the favorite icon for use if a shortcut is added to the home screen. favoriteIcon = icon; // Place the favorite icon in the appBar if it is not null. if (appBar != null) { ImageView imageViewFavoriteIcon = (ImageView) appBar.getCustomView() .findViewById(R.id.favoriteIcon); imageViewFavoriteIcon.setImageBitmap(Bitmap.createScaledBitmap(icon, 64, 64, true)); } } // Enter full screen video @Override public void onShowCustomView(View view, CustomViewCallback callback) { if (appBar != null) { appBar.hide(); } // Show the fullScreenVideoFrameLayout. assert fullScreenVideoFrameLayout != null; //This assert removes the incorrect warning on the following line that fullScreenVideoFrameLayout might be null. fullScreenVideoFrameLayout.addView(view); fullScreenVideoFrameLayout.setVisibility(View.VISIBLE); // Hide the mainWebView. mainWebView.setVisibility(View.GONE); // Hide the ad if this is the free flavor. BannerAd.hideAd(adView); /* SYSTEM_UI_FLAG_HIDE_NAVIGATION hides the navigation bars on the bottom or right of the screen. * SYSTEM_UI_FLAG_FULLSCREEN hides the status bar across the top of the screen. * SYSTEM_UI_FLAG_IMMERSIVE_STICKY makes the navigation and status bars ghosted overlays and automatically rehides them. */ // Set the one flag supported by API >= 14. view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); // Set the two flags that are supported by API >= 16. if (Build.VERSION.SDK_INT >= 16) { view.setSystemUiVisibility( View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN); } // Set all three flags that are supported by API >= 19. if (Build.VERSION.SDK_INT >= 19) { view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } } // Exit full screen video public void onHideCustomView() { if (appBar != null) { appBar.show(); } // Show the mainWebView. mainWebView.setVisibility(View.VISIBLE); // Show the ad if this is the free flavor. BannerAd.showAd(adView); // Hide the fullScreenVideoFrameLayout. assert fullScreenVideoFrameLayout != null; //This assert removes the incorrect warning on the following line that fullScreenVideoFrameLayout might be null. fullScreenVideoFrameLayout.removeAllViews(); fullScreenVideoFrameLayout.setVisibility(View.GONE); } }); // Allow the downloading of files. mainWebView.setDownloadListener(new DownloadListener() { // Launch the Android download manager when a link leads to a download. @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); DownloadManager.Request requestUri = new DownloadManager.Request(Uri.parse(url)); // Add the URL as the description for the download. requestUri.setDescription(url); // Show the download notification after the download is completed. requestUri.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); // Initiate the download and display a Snackbar. downloadManager.enqueue(requestUri); Snackbar.make(findViewById(R.id.mainWebView), R.string.download_started, Snackbar.LENGTH_SHORT) .show(); } }); // Allow pinch to zoom. mainWebView.getSettings().setBuiltInZoomControls(true); // Hide zoom controls. mainWebView.getSettings().setDisplayZoomControls(false); // Initialize the default preference values the first time the program is run. PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // Get the shared preference values. SharedPreferences savedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // Set JavaScript initial status. The default value is false. javaScriptEnabled = savedPreferences.getBoolean("javascript_enabled", false); mainWebView.getSettings().setJavaScriptEnabled(javaScriptEnabled); // Initialize cookieManager. cookieManager = CookieManager.getInstance(); // Set cookies initial status. The default value is false. firstPartyCookiesEnabled = savedPreferences.getBoolean("first_party_cookies_enabled", false); cookieManager.setAcceptCookie(firstPartyCookiesEnabled); // Set third-party cookies initial status if API >= 21. The default value is false. if (Build.VERSION.SDK_INT >= 21) { thirdPartyCookiesEnabled = savedPreferences.getBoolean("third_party_cookies_enabled", false); cookieManager.setAcceptThirdPartyCookies(mainWebView, thirdPartyCookiesEnabled); } // Set DOM storage initial status. The default value is false. domStorageEnabled = savedPreferences.getBoolean("dom_storage_enabled", false); mainWebView.getSettings().setDomStorageEnabled(domStorageEnabled); // Set the user agent initial status. String userAgentString = savedPreferences.getString("user_agent", "Default user agent"); switch (userAgentString) { case "Default user agent": // Do nothing. break; case "Custom user agent": // Set the custom user agent on mainWebView, The default is "PrivacyBrowser/1.0". mainWebView.getSettings() .setUserAgentString(savedPreferences.getString("custom_user_agent", "PrivacyBrowser/1.0")); break; default: // Set the selected user agent on mainWebView. The default is "PrivacyBrowser/1.0". mainWebView.getSettings() .setUserAgentString(savedPreferences.getString("user_agent", "PrivacyBrowser/1.0")); break; } // Set the initial string for JavaScript disabled search. if (savedPreferences.getString("javascript_disabled_search", "https://duckduckgo.com/html/?q=") .equals("Custom URL")) { // Get the custom URL string. The default is "". javaScriptDisabledSearchURL = savedPreferences.getString("javascript_disabled_search_custom_url", ""); } else { // Use the string from javascript_disabled_search. javaScriptDisabledSearchURL = savedPreferences.getString("javascript_disabled_search", "https://duckduckgo.com/html/?q="); } // Set the initial string for JavaScript enabled search. if (savedPreferences.getString("javascript_enabled_search", "https://duckduckgo.com/?q=") .equals("Custom URL")) { // Get the custom URL string. The default is "". javaScriptEnabledSearchURL = savedPreferences.getString("javascript_enabled_search_custom_url", ""); } else { // Use the string from javascript_enabled_search. javaScriptEnabledSearchURL = savedPreferences.getString("javascript_enabled_search", "https://duckduckgo.com/?q="); } // Set homepage initial status. The default value is "https://www.duckduckgo.com". homepage = savedPreferences.getString("homepage", "https://www.duckduckgo.com"); // Set swipe to refresh initial status. The default is true. swipeToRefreshEnabled = savedPreferences.getBoolean("swipe_to_refresh_enabled", true); swipeToRefresh.setEnabled(swipeToRefreshEnabled); // Get the intent information that started the app. final Intent intent = getIntent(); if (intent.getData() != null) { // Get the intent data and convert it to a string. final Uri intentUriData = intent.getData(); formattedUrlString = intentUriData.toString(); } // If formattedUrlString is null assign the homepage to it. if (formattedUrlString == null) { formattedUrlString = homepage; } // Load the initial website. mainWebView.loadUrl(formattedUrlString); // Initialize AdView for the free flavor and request an ad. If this is not the free flavor BannerAd.requestAd() does nothing. adView = findViewById(R.id.adView); BannerAd.requestAd(adView); }
From source file:com.klinker.android.launcher.launcher3.Launcher.java
private void createClickableSearch() { new Handler().postDelayed(new Runnable() { @Override/*w w w . j av a 2 s. c o m*/ public void run() { FrameLayout content = (FrameLayout) findViewById(R.id.search_dummy); View search = new View(Launcher.this); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mQsb.getHeight()); params.topMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 28, getResources().getDisplayMetrics()); search.setLayoutParams(params); search.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (!disableSearch()) { if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); } } return disableSearch(); } }); search.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startSearch("", false, new Bundle(), new Rect()); } }); content.addView(search); } }, 1000); }