Skip to content

Instantly share code, notes, and snippets.

@keithics
Created November 26, 2015 13:19
Show Gist options
  • Save keithics/90eb9e37eb452808c464 to your computer and use it in GitHub Desktop.
Save keithics/90eb9e37eb452808c464 to your computer and use it in GitHub Desktop.
REST Diaglog Class for Android
package com.webninja.usjr.rest;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.IconTextView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.joanzapata.android.iconify.Iconify;
import com.webninja.usjr.R;
/**
* Created by webninja on 1/25/15.
*/
public class RestDialogFragment extends DialogFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout to use as dialog or embedded fragment
View view = inflater.inflate(R.layout.rest_dialog, container, false);
//setStyle(DialogFragment.STYLE_NO_TITLE, R.style.MyDialog);
TextView msg = (TextView) view.findViewById(R.id.message);
msg.setText(getArguments().getString("message"));
return view;
}
/** The system calls this only when creating the layout in a dialog. */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// The only reason you might override this method when using onCreateView() is
// to modify any dialog characteristics. For example, the dialog includes a
// title by default, but your custom layout might not need it. So here you can
// remove the dialog title, but you must call the superclass to get the Dialog.
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
return dialog;
}
@Override
public void onResume() {
ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();
params.width = LayoutParams.MATCH_PARENT;
params.height = LayoutParams.WRAP_CONTENT;
getDialog().getWindow().setAttributes((LayoutParams) params);
super.onResume();
}
public static RestDialogFragment newInstance(String message) {
RestDialogFragment f = new RestDialogFragment();
Bundle args = new Bundle();
args.putString("message", message);
f.setArguments(args);
return f;
}
public void setData(String message,Boolean isError){
try{
TextView msg = (TextView) getView().findViewById(R.id.message);
ProgressBar progressBar = (ProgressBar) getView().findViewById(R.id.progressBar);
Button okayBtn = (Button) getView().findViewById(R.id.okay);
IconTextView icon = (IconTextView) getView().findViewById(R.id.icon);
if(isError){
Iconify.addIcons(icon);
icon.setVisibility(View.VISIBLE);
//okayBtn.setVisibility(View.VISIBLE);
this.setCancelable(true);
}else{
progressBar.setVisibility(View.VISIBLE);
}
msg.setText(message);
}catch (NullPointerException e){
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment