Example usage for android.widget FrameLayout addView

List of usage examples for android.widget FrameLayout addView

Introduction

In this page you can find the example usage for android.widget FrameLayout addView.

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:com.lixplor.rocketpulltorefresh.RefreshLayout.java

/**
 * Init header container view//from  w  ww  .  j  ava  2  s . com
 */
private void initHeaderContainer() {
    FrameLayout headerContainer = new FrameLayout(mContext);
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    params.width = LayoutParams.MATCH_PARENT;
    params.height = LayoutParams.WRAP_CONTENT;
    mHeaderView.measure(0, 0);
    mHeaderHeight = mHeaderView.getMeasuredHeight();
    params.topMargin = -mHeaderHeight;
    headerContainer.addView(mHeaderView);
    addView(headerContainer, 0, params);
}

From source file:com.lixplor.rocketpulltorefresh.RefreshLayout.java

/**
 * Init footer container view/*w w  w  .j  a  v  a2s . c  om*/
 */
private void initFooterContainer() {
    FrameLayout footerContainer = new FrameLayout(mContext);
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    params.width = LayoutParams.MATCH_PARENT;
    params.height = LayoutParams.WRAP_CONTENT;
    mFooterView.measure(0, 0);
    mFooterHeight = mFooterView.getMeasuredHeight();
    params.bottomMargin = -mFooterHeight;
    footerContainer.addView(mFooterView);
    addView(footerContainer, params);
}

From source file:com.android.contacts.group.GroupMembersFragment.java

@Override
protected View inflateView(LayoutInflater inflater, ViewGroup container) {
    final View view = inflater.inflate(R.layout.contact_list_content, /* root */ null);
    final View emptyGroupView = inflater.inflate(R.layout.empty_group_view, null);

    final ImageView image = (ImageView) emptyGroupView.findViewById(R.id.empty_group_image);
    final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) image.getLayoutParams();
    final int screenHeight = getResources().getDisplayMetrics().heightPixels;
    params.setMargins(0,//w w w.  j  a v a2 s  . c  o  m
            screenHeight / getResources().getInteger(R.integer.empty_group_view_image_margin_divisor), 0, 0);
    params.gravity = Gravity.CENTER_HORIZONTAL;
    image.setLayoutParams(params);

    final FrameLayout contactListLayout = (FrameLayout) view.findViewById(R.id.contact_list);
    contactListLayout.addView(emptyGroupView);

    final Button addContactsButton = (Button) emptyGroupView.findViewById(R.id.add_member_button);
    addContactsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivityForResult(
                    GroupUtil.createPickMemberIntent(getContext(), mGroupMetaData, getMemberContactIds()),
                    RESULT_GROUP_ADD_MEMBER);
        }
    });
    return view;
}

From source file:org.quantumbadger.redreader.activities.ImageViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    final boolean solidblack = PrefsUtility.appearance_solidblack(this, sharedPreferences);

    if (solidblack)
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK));

    final Intent intent = getIntent();

    mUrl = General.uriFromString(intent.getDataString());
    final RedditPost src_post = intent.getParcelableExtra("post");

    if (mUrl == null) {
        General.quickToast(this, "Invalid URL. Trying web browser.");
        revertToWeb();/*from  w  ww . j a  v a2s. c o m*/
        return;
    }

    Log.i("ImageViewActivity", "Loading URL " + mUrl.toString());

    final ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);

    final LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(progressBar);

    CacheManager.getInstance(this)
            .makeRequest(mRequest = new CacheRequest(mUrl, RedditAccountManager.getAnon(), null,
                    Constants.Priority.IMAGE_VIEW, 0, CacheRequest.DownloadType.IF_NECESSARY,
                    Constants.FileType.IMAGE, false, false, false, this) {

                private void setContentView(View v) {
                    layout.removeAllViews();
                    layout.addView(v);
                    v.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
                    v.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
                }

                @Override
                protected void onCallbackException(Throwable t) {
                    BugReportActivity.handleGlobalError(context.getApplicationContext(),
                            new RRError(null, null, t));
                }

                @Override
                protected void onDownloadNecessary() {
                    AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                        @Override
                        public void run() {
                            progressBar.setVisibility(View.VISIBLE);
                            progressBar.setIndeterminate(true);
                        }
                    });
                }

                @Override
                protected void onDownloadStarted() {
                }

                @Override
                protected void onFailure(final RequestFailureType type, Throwable t, StatusLine status,
                        final String readableMessage) {

                    final RRError error = General.getGeneralErrorForFailure(context, type, t, status,
                            url.toString());

                    AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                        public void run() {
                            // TODO handle properly
                            mRequest = null;
                            progressBar.setVisibility(View.GONE);
                            layout.addView(new ErrorView(ImageViewActivity.this, error));
                        }
                    });
                }

                @Override
                protected void onProgress(final boolean authorizationInProgress, final long bytesRead,
                        final long totalBytes) {
                    AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                        @Override
                        public void run() {
                            progressBar.setVisibility(View.VISIBLE);
                            progressBar.setIndeterminate(authorizationInProgress);
                            progressBar.setProgress((int) ((100 * bytesRead) / totalBytes));
                        }
                    });
                }

                @Override
                protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, long timestamp,
                        UUID session, boolean fromCache, final String mimetype) {

                    if (mimetype == null
                            || (!Constants.Mime.isImage(mimetype) && !Constants.Mime.isVideo(mimetype))) {
                        revertToWeb();
                        return;
                    }

                    final InputStream cacheFileInputStream;
                    try {
                        cacheFileInputStream = cacheFile.getInputStream();
                    } catch (IOException e) {
                        notifyFailure(RequestFailureType.PARSE, e, null,
                                "Could not read existing cached image.");
                        return;
                    }

                    if (cacheFileInputStream == null) {
                        notifyFailure(RequestFailureType.CACHE_MISS, null, null, "Could not find cached image");
                        return;
                    }

                    if (Constants.Mime.isVideo(mimetype)) {

                        AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                            public void run() {

                                if (mIsDestroyed)
                                    return;
                                mRequest = null;

                                try {
                                    final RelativeLayout layout = new RelativeLayout(context);
                                    layout.setGravity(Gravity.CENTER);

                                    final VideoView videoView = new VideoView(ImageViewActivity.this);

                                    videoView.setVideoURI(cacheFile.getUri());
                                    layout.addView(videoView);
                                    setContentView(layout);

                                    layout.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
                                    layout.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
                                    videoView.setLayoutParams(
                                            new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                                    ViewGroup.LayoutParams.MATCH_PARENT));

                                    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                                        @Override
                                        public void onPrepared(MediaPlayer mp) {
                                            mp.setLooping(true);
                                            videoView.start();
                                        }
                                    });

                                    videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                                        @Override
                                        public boolean onError(final MediaPlayer mediaPlayer, final int i,
                                                final int i1) {
                                            revertToWeb();
                                            return true;
                                        }
                                    });

                                    videoView.setOnTouchListener(new View.OnTouchListener() {
                                        @Override
                                        public boolean onTouch(final View view, final MotionEvent motionEvent) {
                                            finish();
                                            return true;
                                        }
                                    });

                                } catch (OutOfMemoryError e) {
                                    General.quickToast(context, R.string.imageview_oom);
                                    revertToWeb();

                                } catch (Throwable e) {
                                    General.quickToast(context, R.string.imageview_invalid_video);
                                    revertToWeb();
                                }
                            }
                        });

                    } else if (Constants.Mime.isImageGif(mimetype)) {

                        final PrefsUtility.GifViewMode gifViewMode = PrefsUtility
                                .pref_behaviour_gifview_mode(context, sharedPreferences);

                        if (gifViewMode == PrefsUtility.GifViewMode.INTERNAL_BROWSER) {
                            revertToWeb();
                            return;

                        } else if (gifViewMode == PrefsUtility.GifViewMode.EXTERNAL_BROWSER) {
                            AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                                @Override
                                public void run() {
                                    LinkHandler.openWebBrowser(ImageViewActivity.this,
                                            Uri.parse(mUrl.toString()));
                                    finish();
                                }
                            });

                            return;
                        }

                        if (AndroidApi.isIceCreamSandwichOrLater()
                                && gifViewMode == PrefsUtility.GifViewMode.INTERNAL_MOVIE) {

                            AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                                public void run() {

                                    if (mIsDestroyed)
                                        return;
                                    mRequest = null;

                                    try {
                                        final GIFView gifView = new GIFView(ImageViewActivity.this,
                                                cacheFileInputStream);
                                        setContentView(gifView);
                                        gifView.setOnClickListener(new View.OnClickListener() {
                                            public void onClick(View v) {
                                                finish();
                                            }
                                        });

                                    } catch (OutOfMemoryError e) {
                                        General.quickToast(context, R.string.imageview_oom);
                                        revertToWeb();

                                    } catch (Throwable e) {
                                        General.quickToast(context, R.string.imageview_invalid_gif);
                                        revertToWeb();
                                    }
                                }
                            });

                        } else {

                            gifThread = new GifDecoderThread(cacheFileInputStream,
                                    new GifDecoderThread.OnGifLoadedListener() {

                                        public void onGifLoaded() {
                                            AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                                                public void run() {

                                                    if (mIsDestroyed)
                                                        return;
                                                    mRequest = null;

                                                    imageView = new ImageView(context);
                                                    imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                                                    setContentView(imageView);
                                                    gifThread.setView(imageView);

                                                    imageView.setOnClickListener(new View.OnClickListener() {
                                                        public void onClick(View v) {
                                                            finish();
                                                        }
                                                    });
                                                }
                                            });
                                        }

                                        public void onOutOfMemory() {
                                            General.quickToast(context, R.string.imageview_oom);
                                            revertToWeb();
                                        }

                                        public void onGifInvalid() {
                                            General.quickToast(context, R.string.imageview_invalid_gif);
                                            revertToWeb();
                                        }
                                    });

                            gifThread.start();

                        }

                    } else {

                        final ImageTileSource imageTileSource;
                        try {

                            final long bytes = cacheFile.getSize();
                            final byte[] buf = new byte[(int) bytes];

                            try {
                                new DataInputStream(cacheFileInputStream).readFully(buf);
                            } catch (IOException e) {
                                throw new RuntimeException(e);
                            }

                            try {
                                imageTileSource = new ImageTileSourceWholeBitmap(buf);

                            } catch (Throwable t) {
                                Log.e("ImageViewActivity", "Exception when creating ImageTileSource", t);
                                General.quickToast(context, R.string.imageview_decode_failed);
                                revertToWeb();
                                return;
                            }

                        } catch (OutOfMemoryError e) {
                            General.quickToast(context, R.string.imageview_oom);
                            revertToWeb();
                            return;
                        }

                        AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                            public void run() {

                                if (mIsDestroyed)
                                    return;
                                mRequest = null;
                                mImageViewDisplayerManager = new ImageViewDisplayListManager(imageTileSource,
                                        ImageViewActivity.this);
                                surfaceView = new RRGLSurfaceView(ImageViewActivity.this,
                                        mImageViewDisplayerManager);
                                setContentView(surfaceView);

                                surfaceView.setOnClickListener(new View.OnClickListener() {
                                    public void onClick(View v) {
                                        finish();
                                    }
                                });

                                if (mIsPaused) {
                                    surfaceView.onPause();
                                } else {
                                    surfaceView.onResume();
                                }
                            }
                        });
                    }
                }
            });

    final RedditPreparedPost post = src_post == null ? null
            : new RedditPreparedPost(this, CacheManager.getInstance(this), 0, src_post, -1, false, false, false,
                    false, RedditAccountManager.getInstance(this).getDefaultAccount(), false);

    final FrameLayout outerFrame = new FrameLayout(this);
    outerFrame.addView(layout);

    if (post != null) {

        final SideToolbarOverlay toolbarOverlay = new SideToolbarOverlay(this);

        final BezelSwipeOverlay bezelOverlay = new BezelSwipeOverlay(this,
                new BezelSwipeOverlay.BezelSwipeListener() {

                    public boolean onSwipe(BezelSwipeOverlay.SwipeEdge edge) {

                        toolbarOverlay.setContents(
                                post.generateToolbar(ImageViewActivity.this, false, toolbarOverlay));
                        toolbarOverlay.show(edge == BezelSwipeOverlay.SwipeEdge.LEFT
                                ? SideToolbarOverlay.SideToolbarPosition.LEFT
                                : SideToolbarOverlay.SideToolbarPosition.RIGHT);
                        return true;
                    }

                    public boolean onTap() {

                        if (toolbarOverlay.isShown()) {
                            toolbarOverlay.hide();
                            return true;
                        }

                        return false;
                    }
                });

        outerFrame.addView(bezelOverlay);
        outerFrame.addView(toolbarOverlay);

        bezelOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
        bezelOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;

        toolbarOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
        toolbarOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;

    }

    setContentView(outerFrame);
}

From source file:org.zywx.wbpalmstar.engine.universalex.EUExBase.java

/**
 * viewid//from   www.j a v  a 2 s  .  c  o  m
 *
 * @param child
 * @param index
 * @param opid
 */
public final void addSubviewToContainer(final View child, final int index, final String opid,
        final FrameLayout.LayoutParams parms) {
    if (null == mBrwView || opid == null || index < 0 || parms == null) {
        return;
    }
    ((EBrowserActivity) mContext).runOnUiThread(new Runnable() {

        @Override
        public void run() {
            EBrowserWindow mWindow = mBrwView.getBrowserWindow();
            int count = mWindow.getChildCount();
            int l = (int) (parms.leftMargin);
            int t = (int) (parms.topMargin);
            int w = parms.width;
            int h = parms.height;
            for (int i = 0; i < count; i++) {
                View view = mWindow.getChildAt(i);
                if (view instanceof ContainerViewPager) {
                    final ContainerViewPager pager = (ContainerViewPager) view;
                    if (opid.equals(pager.getContainerVO().getId())) {
                        ContainerAdapter adapter = (ContainerAdapter) pager.getAdapter();
                        Vector<FrameLayout> views = adapter.getViewList();
                        boolean needAnim = views.size() == 0;//view
                        child.setLayoutParams(parms);
                        FrameLayout layout = new FrameLayout(mContext);
                        layout.addView(child);
                        if (views.size() <= index) {
                            for (int j = views.size(); j <= index; j++) {
                                if (j == index) {
                                    views.add(layout);
                                } else {
                                    views.add(new FrameLayout(mContext));
                                }
                            }
                        } else {
                            views.set(index, layout);
                        }
                        adapter.setViewList(views);
                        adapter.notifyDataSetChanged();
                        if (needAnim && pager.getContainerVO().getAnimTime() != 0) {
                            startAnimationDelay(pager, child);
                        }
                        return;
                    } //end equals opid
                } //end instanceof
            } //end for
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(w, h);
            lp.leftMargin = l;
            lp.topMargin = t;
            addViewToCurrentWindow(child, lp);
        }// end run 
    });// end runOnUI
}

From source file:com.air.mobilebrowser.BrowserActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ttsPlayer = new TTSPlayer(this);

    // Allow for out-of-band additions to thread queue (mainly for cleanup)
    mHandler = new Handler();

    // Prevents user from taking screenshots. 
    getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    // Load layout
    mWebView = new AIRWebView(this, this);
    mWebView.requestFocus(View.FOCUS_DOWN);

    setContentView(R.layout.activity_browser);
    FrameLayout layout = (FrameLayout) findViewById(R.id.sec_webview);
    layout.addView(((AIRWebView) mWebView).getLayout());

    // Initialize device monitoring 
    mDeviceStatus = new DeviceStatus(this, this);
    mDeviceStatus.registerReceivers(this);

    // By default, lock to landscape
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    mDeviceStatus.lockedOrientation = "landscape";

    // Configure the webview 
    configureWebView(mWebView);/*  www.jav  a  2s  . co  m*/

    // Configure Debug Console
    if (mIsDebugEnabled) {
        findViewById(R.id.slidingDrawer1).setVisibility(View.VISIBLE);
        findViewById(R.id.addressBarWrapper).setVisibility(View.VISIBLE);

        findViewById(R.id.goButton).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                String url = ((EditText) findViewById(R.id.address_bar)).getText().toString();
                mWebView.loadUrl(url);
            }
        });
    }

    // Load the content 
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    String url = preferences.getString("pref_default_url", getString(R.string.url_default_location));

    // For testing, uncomment the following line to use a custom url: 

    // Check for Internet connectivity
    if (mDeviceStatus.connectivity == DeviceStatus.CONNECTIVITY_CONNECTED) {
        mWebView.loadUrl(url);
    } else {
        mWebView.loadUrl("about:none");
    }

    // Register BroadcastListener for service intents
    mSBReceiver = new SBReceiver(this);
    LocalBroadcastManager.getInstance(super.getApplicationContext()).registerReceiver(mSBReceiver,
            new IntentFilter(super.getResources().getString(R.string.intent_black_logtag)));
    LocalBroadcastManager.getInstance(super.getApplicationContext()).registerReceiver(mSBReceiver,
            new IntentFilter(super.getResources().getString(R.string.intent_micmutechanged)));
    LocalBroadcastManager.getInstance(super.getApplicationContext()).registerReceiver(mSBReceiver,
            new IntentFilter(super.getResources().getString(R.string.intent_keyboardchange)));
    // add receiver for bluetooth keyboard connection/disconnection events
    LocalBroadcastManager.getInstance(super.getApplicationContext()).registerReceiver(mSBReceiver,
            new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED));
    LocalBroadcastManager.getInstance(super.getApplicationContext()).registerReceiver(mSBReceiver,
            new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));

    IntentFilter testFilter = new IntentFilter(Intent.CATEGORY_HOME);

    super.getApplicationContext().registerReceiver(mSBReceiver, testFilter);

    // Get AudioManger
    mAudioManager = (AudioManager) super.getApplicationContext().getSystemService(Context.AUDIO_SERVICE);

    // Configure JS Command Processing
    configureJSCmdHandling();

    // Begin monitoring for focus change. 
    startService(new Intent(getApplicationContext(), ActivityWatchService.class));
}

From source file:dk.nordfalk.aktivitetsliste.PagerSlidingTabStrip.java

private void addIconTabBdeTekstOgBillede(final int position, int resId, String title) {
    FrameLayout tabfl = new FrameLayout(getContext());
    ImageView tabi = new ImageView(getContext());
    tabi.setContentDescription(title);/*from   w w  w  . ja va2s . co m*/
    tabi.setImageResource(resId);
    tabi.setVisibility(View.INVISIBLE);
    TextView tabt = new TextView(getContext());
    tabt.setText(title);
    tabt.setGravity(Gravity.CENTER);
    tabt.setSingleLine();

    tabfl.addView(tabi);
    tabfl.addView(tabt);

    LayoutParams lp = (LayoutParams) tabi.getLayoutParams();
    lp.gravity = Gravity.CENTER;
    lp = (LayoutParams) tabt.getLayoutParams();
    lp.width = lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
    lp.gravity = Gravity.CENTER;

    addTab(position, tabfl);
}

From source file:org.telegram.ui.myLocationSettingsActivity.java

@Override
public View createView(LayoutInflater inflater) {
    if (fragmentView == null) {
        actionBar.setBackButtonImage(R.drawable.ic_ab_back);
        actionBar.setAllowOverlayTitle(true);
        actionBar.setTitle("My Places");
        actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
            @Override//from  w  w w  .  ja  v  a 2s . c  o m
            public void onItemClick(int id) {
                if (id == -1) {
                    finishFragment();
                }
            }
        });

        listAdapter = new ListAdapter(getParentActivity());

        fragmentView = new FrameLayout(getParentActivity());
        FrameLayout frameLayout = (FrameLayout) fragmentView;
        frameLayout.setBackgroundColor(0xfff0f0f0);

        ListView listView = new ListView(getParentActivity());
        listView.setDivider(null);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
        layoutParams.height = FrameLayout.LayoutParams.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 == homeRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle("Home");
                    final ViewGroup.LayoutParams lparams = new ViewGroup.LayoutParams(50, 30);
                    final EditText input = new EditText(getParentActivity());
                    input.setHint("Insert city");
                    input.setLayoutParams(lparams);
                    builder.setView(input);
                    builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (input.getText().toString().trim().length() > 0) {
                                String city = input.getText().toString().trim();
                                try {
                                    Bundle locationHome = new getCoordinates().execute(city).get();
                                    String latHome = locationHome.getString("lat");
                                    String lonHome = locationHome.getString("lon");
                                    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext
                                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                                    SharedPreferences.Editor editor = sharedPreferences.edit();
                                    editor.putString("latHome", latHome);
                                    editor.putString("longHome", lonHome);
                                    editor.commit();
                                    Log.i(TAG, "fine! " + lonHome);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                } catch (ExecutionException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT)
                                        .show();
                            }

                        }
                    });
                    builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show();
                        }
                    });
                    showAlertDialog(builder);
                } else if (i == workRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle("Work");
                    final EditText input = new EditText(getParentActivity());
                    input.setHint("Insert city");
                    builder.setView(input);
                    builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (input.getText().toString().trim().length() > 0) {
                                String city = input.getText().toString().trim();
                                try {
                                    Bundle locationWork = new getCoordinates().execute(city).get();
                                    String latWork = locationWork.getString("lat");
                                    String lonWork = locationWork.getString("lon");
                                    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext
                                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                                    SharedPreferences.Editor editor = sharedPreferences.edit();
                                    editor.putString("latWork", latWork);
                                    editor.putString("longWork", lonWork);
                                    editor.commit();
                                    Log.i(TAG, "fine! " + latWork);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                } catch (ExecutionException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT)
                                        .show();
                            }

                        }
                    });
                    builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show();
                        }
                    });
                    showAlertDialog(builder);
                } else if (i == entertainmentRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle("Entertainment");
                    final EditText input = new EditText(getParentActivity());
                    input.setHint("Insert city");
                    builder.setView(input);
                    builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (input.getText().toString().trim().length() > 0) {
                                String city = input.getText().toString().trim();
                                try {
                                    Bundle locationEntertainment = new getCoordinates().execute(city).get();
                                    String latEntertainment = locationEntertainment.getString("lat");
                                    String lonEntertainment = locationEntertainment.getString("lon");
                                    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext
                                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                                    SharedPreferences.Editor editor = sharedPreferences.edit();
                                    editor.putString("latEntertainment", latEntertainment);
                                    editor.putString("longEntertainment", lonEntertainment);
                                    editor.commit();
                                    Log.i(TAG, "fine! " + latEntertainment);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                } catch (ExecutionException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT)
                                        .show();
                            }

                        }
                    });
                    builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show();
                        }
                    });
                    showAlertDialog(builder);
                }
                //TODO find a solution for commuteRow as well!!
            }
        });
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:com.github.jvanhie.discogsscrobbler.RecentlyPlayedFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    //setup list view
    mList = new ListView(getActivity());
    mList.setId(android.R.id.list);/*ww w . j a  v  a 2s. c o m*/

    mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            onListItemClick(view, i, l);
        }
    });

    //create superframe for adding list and empty view
    FrameLayout superFrame = new FrameLayout(getActivity());
    FrameLayout.LayoutParams layoutparams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    superFrame.setLayoutParams(layoutparams);
    View emptyView = inflater.inflate(R.layout.fragment_empty, container, false);
    ((TextView) emptyView.findViewById(R.id.empty_heading)).setText("No recently played albums");
    ((TextView) emptyView.findViewById(R.id.empty_text)).setText(
            "Your recently played list is empty. Once you start registering your played records they'll end up here");

    /*initialize list with local discogs collection*/
    if (mDiscogs == null)
        mDiscogs = Discogs.getInstance(getActivity());
    loadList();

    superFrame.addView(emptyView);
    mList.setEmptyView(emptyView);
    superFrame.addView(mList);

    return superFrame;
}

From source file:org.quantumbadger.redreader.fragments.CommentListingFragment.java

@Override
public void onCommentListingRequestPostDownloaded(final RedditPreparedPost post) {

    final Context context = getActivity();

    if (mPost == null) {

        final RRThemeAttributes attr = new RRThemeAttributes(context);

        mPost = post;/*from   w ww .j a va2s  . c o  m*/
        isArchived = post.isArchived;

        final RedditPostHeaderView postHeader = new RedditPostHeaderView(getActivity(), this.mPost);

        mCommentListingManager.addPostHeader(postHeader);
        ((LinearLayoutManager) mRecyclerView.getLayoutManager()).scrollToPositionWithOffset(0, 0);

        if (post.src.getSelfText() != null) {
            final ViewGroup selfText = post.src.getSelfText().buildView(getActivity(), attr.rrMainTextCol,
                    14f * mCommentFontScale, mShowLinkButtons);
            selfText.setFocusable(false);
            selfText.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);

            final int paddingPx = General.dpToPixels(context, 10);
            final FrameLayout paddingLayout = new FrameLayout(context);
            final TextView collapsedView = new TextView(context);
            collapsedView.setText("[ + ]  " + getActivity().getString(R.string.collapsed_self_post));
            collapsedView.setVisibility(View.GONE);
            collapsedView.setPadding(paddingPx, paddingPx, paddingPx, paddingPx);
            paddingLayout.addView(selfText);
            paddingLayout.addView(collapsedView);
            paddingLayout.setPadding(paddingPx, paddingPx, paddingPx, paddingPx);

            paddingLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (selfText.getVisibility() == View.GONE) {
                        selfText.setVisibility(View.VISIBLE);
                        collapsedView.setVisibility(View.GONE);
                    } else {
                        selfText.setVisibility(View.GONE);
                        collapsedView.setVisibility(View.VISIBLE);
                    }

                }
            });
            // TODO mListHeaderNotifications.setBackgroundColor(Color.argb(35, 128, 128, 128));

            mCommentListingManager.addPostSelfText(paddingLayout);
        }

        if (!General.isTablet(context, PreferenceManager.getDefaultSharedPreferences(context))) {
            getActivity().setTitle(post.src.getTitle());
        }

        if (mCommentListingManager.isSearchListing()) {
            final CommentSubThreadView searchCommentThreadView = new CommentSubThreadView(getActivity(),
                    mAllUrls.get(0).asPostCommentListURL(), R.string.comment_header_search_thread_title);

            mCommentListingManager.addNotification(searchCommentThreadView);
        } else if (!mAllUrls.isEmpty() && mAllUrls.get(0).pathType() == RedditURLParser.POST_COMMENT_LISTING_URL
                && mAllUrls.get(0).asPostCommentListURL().commentId != null) {

            final CommentSubThreadView specificCommentThreadView = new CommentSubThreadView(getActivity(),
                    mAllUrls.get(0).asPostCommentListURL(), R.string.comment_header_specific_thread_title);

            mCommentListingManager.addNotification(specificCommentThreadView);
        }

        // TODO pref (currently 10 mins)
        if (mCachedTimestamp != null && RRTime.since(mCachedTimestamp) > 10 * 60 * 1000) {

            final TextView cacheNotif = (TextView) LayoutInflater.from(getActivity())
                    .inflate(R.layout.cached_header, null, false);
            cacheNotif.setText(getActivity().getString(R.string.listing_cached,
                    RRTime.formatDateTime(mCachedTimestamp, getActivity())));
            mCommentListingManager.addNotification(cacheNotif);
        }
    }
}