Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for DialogFragment and sample code provided #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions progressfragment-native-sample/res/layout/view_header.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView android:layout_width="match_parent"
android:layout_height="56dp"
android:gravity="center_vertical"
android:singleLine="true"
android:ellipsize="marquee"
android:padding="8dp"
android:textSize="18sp"
android:textStyle="bold"
android:text="@string/title"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/black"/>
</LinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.devspark.progressfragment.sample;

import android.app.DialogFragment;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.devspark.progressfragment.ProgressDialogFragment;

/**
* Sample implementation of {@link ProgressDialogFragment}.
*/
public class DefaultDialogProgressFragment extends ProgressDialogFragment {
private View mHeaderView;
private View mContentView;
private Handler mHandler;
private Runnable mShowContentRunnable = new Runnable() {

@Override
public void run() {
setContentShown(true);
}

};

public static DefaultDialogProgressFragment newInstance() {
DefaultDialogProgressFragment fragment = new DefaultDialogProgressFragment();
return fragment;
}

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

setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mHeaderView = inflater.inflate(R.layout.view_header, container, false);
mContentView = inflater.inflate(R.layout.view_content, container, false);
return super.onCreateView(inflater, container, savedInstanceState);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Setup header view
setHeaderView(mHeaderView);
// Setup content view
setContentView(mContentView);
// Setup text for empty content
setEmptyText(R.string.empty);
obtainData();
}

@Override
public void onDestroyView() {
super.onDestroyView();
mHandler.removeCallbacks(mShowContentRunnable);
}

private void obtainData() {
// Show indeterminate progress
setContentShown(false);

mHandler = new Handler();
mHandler.postDelayed(mShowContentRunnable, 3000);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.devspark.progressfragment.sample;

import android.app.DialogFragment;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.devspark.progressfragment.ProgressDialogFragment;

public class EmptyContentDialogProgressFragment extends ProgressDialogFragment {
private View mHeaderView;
private View mContentView;
private Handler mHandler;
private Runnable mShowContentRunnable = new Runnable() {

@Override
public void run() {
setContentEmpty(true);
setContentShown(true);
}

};

public static EmptyContentDialogProgressFragment newInstance() {
EmptyContentDialogProgressFragment fragment = new EmptyContentDialogProgressFragment();
return fragment;
}

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

setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mHeaderView = inflater.inflate(R.layout.view_header, container, false);
mContentView = inflater.inflate(R.layout.view_content, container, false);
return super.onCreateView(inflater, container, savedInstanceState);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Setup header view
setHeaderView(mHeaderView);
// Setup content view
setContentView(mContentView);
// Setup text for empty content
setEmptyText(R.string.empty);
obtainData();
}

@Override
public void onDestroyView() {
super.onDestroyView();
mHandler.removeCallbacks(mShowContentRunnable);
}

private void obtainData() {
// Show indeterminate progress
setContentShown(false);

mHandler = new Handler();
mHandler.postDelayed(mShowContentRunnable, 3000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
*/
public class MainActivity extends ListActivity {

private String[] examples = new String[]{"Default", "Empty content", "Custom layout", "List", "Grid"};
private String[] examples = new String[]{"Default", "Empty content", "Custom layout", "List", "Grid",
"DialogFragment", "Empty content DialogFragment"};

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -57,6 +58,12 @@ protected void onListItemClick(ListView l, View v, int position, long id) {
case 4:
intent.putExtra(ProgressActivity.EXTRA_FRAGMENT, ProgressActivity.FRAGMENT_GRID);
break;
case 5:
intent.putExtra(ProgressActivity.EXTRA_FRAGMENT, ProgressActivity.DIALOG_FRAGMENT);
break;
case 6:
intent.putExtra(ProgressActivity.EXTRA_FRAGMENT, ProgressActivity.DIALOG_EMPTY_CONTENT);
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class ProgressActivity extends Activity {
public static final int FRAGMENT_CUSTOM_LAYOUT = 2;
public static final int FRAGMENT_LIST = 3;
public static final int FRAGMENT_GRID = 4;
public static final int DIALOG_FRAGMENT = 5;
public static final int DIALOG_EMPTY_CONTENT = 6;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -42,11 +44,21 @@ protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
new ActionBarHelper().setDisplayHomeAsUpEnabled(true);
}
int fragmentId = getIntent().getIntExtra(EXTRA_FRAGMENT, FRAGMENT_DEFAULT);
if (fragmentId == DIALOG_FRAGMENT) {
DefaultDialogProgressFragment df = DefaultDialogProgressFragment.newInstance();
df.show(getFragmentManager(), "DefaultDialogProgressFragment");
return;
} else if (fragmentId == DIALOG_EMPTY_CONTENT) {
EmptyContentDialogProgressFragment df = EmptyContentDialogProgressFragment.newInstance();
df.show(getFragmentManager(), "EmptyContentDialogProgressFragment");
return;
}

// Check what fragment is shown, replace if needed.
Fragment fragment = getFragmentManager().findFragmentById(android.R.id.content);
if (fragment == null) {
// Make new fragment to show.
int fragmentId = getIntent().getIntExtra(EXTRA_FRAGMENT, FRAGMENT_DEFAULT);
switch (fragmentId) {
case FRAGMENT_DEFAULT:
fragment = DefaultProgressFragment.newInstance();
Expand Down
50 changes: 50 additions & 0 deletions progressfragment-native/res/layout/fragment_dialog_progress.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:id="@+id/header_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<LinearLayout
android:id="@+id/progress_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/header_container"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">

<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:id="@android:id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<TextView
android:id="@+id/progress_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="4dip"
android:singleLine="true"
android:visibility="gone"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</LinearLayout>

<FrameLayout
android:id="@+id/content_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/header_container">

<TextView
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</FrameLayout>

</RelativeLayout>
Loading