Replaced error message dialog with card on dashboard

This commit is contained in:
Bars107 2014-12-02 14:43:46 +02:00
parent f0a9e00ddb
commit 83a685d0c0
4 changed files with 137 additions and 40 deletions

View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@drawable/bg_cardui"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/error_header"
android:layout_height="wrap_content"
android:padding="12dp"
android:layout_width="match_parent"
android:gravity="center_horizontal"
android:textColor="@color/dashboard_black"
android:layout_gravity="center_horizontal"/>
<View android:layout_width="match_parent"
android:background="@color/dashboard_divider"
android:layout_height="1dp"/>
<LinearLayout android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="40dp">
<Button android:id="@+id/error_btn"
android:layout_width="0dp"
android:layout_weight="1"
android:text="@string/send_report"
style="@style/DashboardGeneralButton"/>
<View android:layout_width="1dp"
android:background="@color/dashboard_divider"
android:layout_height="match_parent"/>
<Button android:id="@+id/error_cancel"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/default_buttons_cancel"
style="@style/DashboardGeneralButton"/>
</LinearLayout>
</LinearLayout>

View file

@ -175,6 +175,15 @@ public class DashboardActivity extends BaseDownloadActivity {
setupContributionVersion(); setupContributionVersion();
} }
private void addErrorFragment(){
android.support.v4.app.FragmentManager manager = getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction = manager.beginTransaction();
if (manager.findFragmentByTag(DashErrorFragment.TAG) == null){
DashErrorFragment errorFragment = new DashErrorFragment();
fragmentTransaction.add(R.id.content, errorFragment, DashErrorFragment.TAG).commit();
}
}
public static void showAboutDialog(final Activity activity, final OsmandApplication app) { public static void showAboutDialog(final Activity activity, final OsmandApplication app) {
Builder bld = new AlertDialog.Builder(activity); Builder bld = new AlertDialog.Builder(activity);
bld.setTitle(R.string.about_settings); bld.setTitle(R.string.about_settings);
@ -306,38 +315,7 @@ public class DashboardActivity extends BaseDownloadActivity {
final File file = app.getAppPath(OsmandApplication.EXCEPTION_PATH); final File file = app.getAppPath(OsmandApplication.EXCEPTION_PATH);
if (file.exists() && file.length() > 0) { if (file.exists() && file.length() > 0) {
if (size != file.length() && !firstTime) { if (size != file.length() && !firstTime) {
String msg = MessageFormat.format(getString(R.string.previous_run_crashed), OsmandApplication.EXCEPTION_PATH); addErrorFragment();
Builder builder = new AccessibleAlertBuilder(DashboardActivity.this);
builder.setMessage(msg).setNeutralButton(getString(R.string.close), null);
builder.setPositiveButton(R.string.send_report, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "osmand.app+crash@gmail.com" }); //$NON-NLS-1$
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$
intent.putExtra(Intent.EXTRA_SUBJECT, "OsmAnd bug"); //$NON-NLS-1$
StringBuilder text = new StringBuilder();
text.append("\nDevice : ").append(Build.DEVICE); //$NON-NLS-1$
text.append("\nBrand : ").append(Build.BRAND); //$NON-NLS-1$
text.append("\nModel : ").append(Build.MODEL); //$NON-NLS-1$
text.append("\nProduct : ").append(Build.PRODUCT); //$NON-NLS-1$
text.append("\nBuild : ").append(Build.DISPLAY); //$NON-NLS-1$
text.append("\nVersion : ").append(Build.VERSION.RELEASE); //$NON-NLS-1$
text.append("\nApp Version : ").append(Version.getAppName(app)); //$NON-NLS-1$
try {
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
if (info != null) {
text.append("\nApk Version : ").append(info.versionName).append(" ").append(info.versionCode); //$NON-NLS-1$ //$NON-NLS-2$
}
} catch (NameNotFoundException e) {
}
intent.putExtra(Intent.EXTRA_TEXT, text.toString());
startActivity(Intent.createChooser(intent, getString(R.string.send_report)));
}
});
builder.show();
} }
getPreferences(MODE_WORLD_WRITEABLE).edit().putLong(EXCEPTION_FILE_SIZE, file.length()).commit(); getPreferences(MODE_WORLD_WRITEABLE).edit().putLong(EXCEPTION_FILE_SIZE, file.length()).commit();
} else { } else {

View file

@ -0,0 +1,83 @@
package net.osmand.plus.dashboard;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.DashboardActivity;
import net.osmand.plus.helpers.FontCache;
import java.io.File;
import java.text.MessageFormat;
/**
* Created by dummy on 02.12.14.
*/
public class DashErrorFragment extends DashBaseFragment {
public static final String TAG = "DASH_ERROR_FRAGMENT";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_error_fragment, container, false);
String msg = MessageFormat.format(getString(R.string.previous_run_crashed), OsmandApplication.EXCEPTION_PATH);
Typeface typeface = FontCache.getRobotoMedium(getActivity());
TextView message =((TextView) view.findViewById(R.id.error_header));
message.setTypeface(typeface);
message.setText(msg);
Button errorBtn = ((Button) view.findViewById(R.id.error_btn));
errorBtn.setTypeface(typeface);
errorBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "osmand.app+crash@gmail.com" }); //$NON-NLS-1$
File file = getMyApplication().getAppPath(OsmandApplication.EXCEPTION_PATH);
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$
intent.putExtra(Intent.EXTRA_SUBJECT, "OsmAnd bug"); //$NON-NLS-1$
StringBuilder text = new StringBuilder();
text.append("\nDevice : ").append(Build.DEVICE); //$NON-NLS-1$
text.append("\nBrand : ").append(Build.BRAND); //$NON-NLS-1$
text.append("\nModel : ").append(Build.MODEL); //$NON-NLS-1$
text.append("\nProduct : ").append(Build.PRODUCT); //$NON-NLS-1$
text.append("\nBuild : ").append(Build.DISPLAY); //$NON-NLS-1$
text.append("\nVersion : ").append(Build.VERSION.RELEASE); //$NON-NLS-1$
text.append("\nApp Version : ").append(Version.getAppName(getMyApplication())); //$NON-NLS-1$
try {
PackageInfo info = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
if (info != null) {
text.append("\nApk Version : ").append(info.versionName).append(" ").append(info.versionCode); //$NON-NLS-1$ //$NON-NLS-2$
}
} catch (PackageManager.NameNotFoundException e) {
}
intent.putExtra(Intent.EXTRA_TEXT, text.toString());
startActivity(Intent.createChooser(intent, getString(R.string.send_report)));
}
});
Button cancelBtn = ((Button) view.findViewById(R.id.error_cancel));
cancelBtn.setTypeface(typeface);
cancelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DashboardActivity dashboardActivity =((DashboardActivity)getSherlockActivity());
if (dashboardActivity != null) {
dashboardActivity.getSupportFragmentManager().beginTransaction().remove(DashErrorFragment.this).commit();
}
}
});
return view;
}
}

View file

@ -34,7 +34,6 @@ public class DashMapFragment extends DashBaseFragment implements IMapDownloader
public static final String TAG = "DASH_MAP_FRAGMENT"; public static final String TAG = "DASH_MAP_FRAGMENT";
private OsmandMapTileView osmandMapTileView; private OsmandMapTileView osmandMapTileView;
OsmandApplication app;
@Override @Override
public void onDestroy() { public void onDestroy() {
@ -67,8 +66,6 @@ public class DashMapFragment extends DashBaseFragment implements IMapDownloader
}); });
app = (OsmandApplication) getSherlockActivity().getApplication();
return view; return view;
} }
@ -109,8 +106,8 @@ public class DashMapFragment extends DashBaseFragment implements IMapDownloader
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
view.findViewById(R.id.MapView).setVisibility(View.GONE); view.findViewById(R.id.MapView).setVisibility(View.GONE);
if(app.isApplicationInitializing()) { if(getMyApplication().isApplicationInitializing()) {
app.checkApplicationIsBeingInitialized(getActivity(), (TextView) view.findViewById(R.id.ProgressMessage), getMyApplication().checkApplicationIsBeingInitialized(getActivity(), (TextView) view.findViewById(R.id.ProgressMessage),
(ProgressBar) view.findViewById(R.id.ProgressBar), new Runnable() { (ProgressBar) view.findViewById(R.id.ProgressBar), new Runnable() {
@Override @Override
public void run() { public void run() {
@ -125,9 +122,11 @@ public class DashMapFragment extends DashBaseFragment implements IMapDownloader
private void applicationInitialized(View view) { private void applicationInitialized(View view) {
view.findViewById(R.id.loading).setVisibility(View.GONE); view.findViewById(R.id.loading).setVisibility(View.GONE);
DashboardActivity dashboardActivity =((DashboardActivity)getSherlockActivity()); DashboardActivity dashboardActivity =((DashboardActivity)getSherlockActivity());
if (dashboardActivity != null){
dashboardActivity.updateDownloads(); dashboardActivity.updateDownloads();
view.findViewById(R.id.MapView).setVisibility(View.VISIBLE); view.findViewById(R.id.MapView).setVisibility(View.VISIBLE);
} }
}
@Override @Override
public void tileDownloaded(DownloadRequest request) { public void tileDownloaded(DownloadRequest request) {