Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

better location management

  • Loading branch information...
commit 892b1b6d2731360e29b7dc34c62a2eae4f90148d 1 parent 6d78d49
@mariotaku authored
View
0  res/drawable-hdpi/two_panes_shadow_right.9.png → res/drawable-hdpi/right_pane_shadow.9.png
File renamed without changes
View
BIN  res/drawable-hdpi/two_panes_shadow_left.9.png
Deleted file not rendered
View
0  res/drawable-mdpi/two_panes_shadow_right.9.png → res/drawable-mdpi/right_pane_shadow.9.png
File renamed without changes
View
BIN  res/drawable-mdpi/two_panes_shadow_left.9.png
Deleted file not rendered
View
0  res/drawable-xhdpi/two_panes_shadow_right.9.png → res/drawable-xhdpi/right_pane_shadow.9.png
File renamed without changes
View
BIN  res/drawable-xhdpi/two_panes_shadow_left.9.png
Deleted file not rendered
View
3  res/layout/base_dual_pane.xml
@@ -37,8 +37,7 @@
<View
android:layout_width="0dp"
android:layout_height="match_parent"
- android:layout_weight="@integer/pane_left_shadow_weight"
- android:background="@drawable/two_panes_shadow_left"/>
+ android:layout_weight="@integer/pane_left_shadow_weight"/>
</LinearLayout>
<org.mariotaku.twidere.view.SlidePane
View
3  res/layout/search_dual_pane.xml
@@ -47,8 +47,7 @@
<View
android:layout_width="0dp"
android:layout_height="match_parent"
- android:layout_weight="@integer/pane_left_shadow_weight"
- android:background="@drawable/two_panes_shadow_left"/>
+ android:layout_weight="@integer/pane_left_shadow_weight"/>
</LinearLayout>
<org.mariotaku.twidere.view.SlidePane
View
58 src/edu/ucdavis/earlybird/UCDService.java
@@ -7,9 +7,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.location.Criteria;
import android.location.Location;
-import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
@@ -22,9 +20,8 @@
public static final long LOCATION_PERIOD_IN_MILLI = 15 * 60 * 1000;
public static final String ACTION_GET_LOCATION = "edu.ucdavis.earlybird.GET_LOCATION";
private LocationManager mLocationManager;
- private FineLocationListener mFineLocationListener;
private AlarmManager mAlarmManager;
- private AlarmReceiver mAlarmReceiver;
+ private LocationUpdateReceiver mAlarmReceiver;
private PendingIntent locationIntent;
private PendingIntent uploadIntent;
@@ -39,13 +36,12 @@ public void onCreate() {
ProfilingUtil.log("onCreate");
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
- mFineLocationListener = new FineLocationListener();
mAlarmManager = (AlarmManager) getSystemService(Service.ALARM_SERVICE);
- mAlarmReceiver = new AlarmReceiver();
- final IntentFilter myFilter = new IntentFilter();
- myFilter.addAction(ACTION_GET_LOCATION);
- registerReceiver(mAlarmReceiver, myFilter);
+ mAlarmReceiver = new LocationUpdateReceiver();
+ final IntentFilter filter = new IntentFilter();
+ filter.addAction(ACTION_GET_LOCATION);
+ registerReceiver(mAlarmReceiver, filter);
final Intent intent = new Intent(ACTION_GET_LOCATION);
locationIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
@@ -66,45 +62,23 @@ public void onDestroy() {
super.onDestroy();
}
- private final class AlarmReceiver extends BroadcastReceiver {
+ private final class LocationUpdateReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
+ if (mLocationManager == null) return;
ProfilingUtil.log("AlarmReceiver");
- final Criteria criteria = new Criteria();
- criteria.setAccuracy(Criteria.ACCURACY_COARSE);
- final String provider = mLocationManager.getBestProvider(criteria, true);
- if (provider != null) {
- mLocationManager.requestLocationUpdates(provider, 0, 0, mFineLocationListener);
+ final String provider = LocationManager.NETWORK_PROVIDER;
+ if (mLocationManager.isProviderEnabled(provider)) {
+ final Location location = mLocationManager.getLastKnownLocation(provider);
+ if (location != null) {
+ ProfilingUtil.profiling(UCDService.this, ProfilingUtil.FILE_NAME_LOCATION, location.getTime() + ","
+ + location.getLatitude() + "," + location.getLongitude() + "," + location.getProvider());
+ ProfilingUtil.log(location.getTime() + "," + location.getLatitude() + "," + location.getLongitude() + ","
+ + location.getProvider());
+ }
}
}
}
- private final class FineLocationListener implements LocationListener {
-
- @Override
- public void onLocationChanged(final Location location) {
- ProfilingUtil.profiling(UCDService.this, ProfilingUtil.FILE_NAME_LOCATION, location.getTime() + ","
- + location.getLatitude() + "," + location.getLongitude() + "," + location.getProvider());
- ProfilingUtil.log(location.getTime() + "," + location.getLatitude() + "," + location.getLongitude() + ","
- + location.getProvider());
-
- mLocationManager.removeUpdates(mFineLocationListener);
- }
-
- @Override
- public void onProviderDisabled(final String provider) {
- ProfilingUtil.log("onProviderDisabled");
- }
-
- @Override
- public void onProviderEnabled(final String provider) {
- ProfilingUtil.log("onProviderEnabled");
- }
-
- @Override
- public void onStatusChanged(final String provider, final int status, final Bundle extras) {
- ProfilingUtil.log("onStatusChanged");
- }
- }
}
View
18 src/org/mariotaku/twidere/activity/ComposeActivity.java
@@ -224,6 +224,7 @@ public void onActivityResult(final int requestCode, final int resultCode, final
}
final String text = extras.getString(INTENT_KEY_TEXT);
final String append = extras.getString(INTENT_KEY_APPEND_TEXT);
+ final Uri image_uri = extras.getParcelable(INTENT_KEY_IMAGE_URI);
if (text != null) {
mEditText.setText(text);
mText = parseString(mEditText.getText());
@@ -231,6 +232,12 @@ public void onActivityResult(final int requestCode, final int resultCode, final
mEditText.append(append);
mText = parseString(mEditText.getText());
}
+ final File file = image_uri == null ? null : new File(getImagePathFromUri(this, image_uri));
+ if (file != null && file.exists()) {
+ mImageUri = Uri.fromFile(file);
+ reloadAttachedImageThumbnail(file);
+ }
+ setMenu(mMenuBar.getMenu());
}
break;
}
@@ -468,7 +475,10 @@ public void onLoadFinished(final Loader<Bitmap> loader, final Bitmap data) {
/** Sets the mRecentLocation object to the current location of the device **/
@Override
public void onLocationChanged(final Location location) {
- mRecentLocation = location != null ? new ParcelableLocation(location) : null;
+ if (mRecentLocation == null) {
+ mRecentLocation = location != null ? new ParcelableLocation(location) : null;
+ setSupportProgressBarIndeterminateVisibility(false);
+ }
}
@Override
@@ -615,6 +625,7 @@ public boolean onPrepareOptionsMenu(final Menu menu) {
@Override
public void onProviderDisabled(final String provider) {
+ setSupportProgressBarIndeterminateVisibility(false);
}
@Override
@@ -675,7 +686,6 @@ protected void onStart() {
}
final int text_size = mPreferences.getInt(PREFERENCE_KEY_TEXT_SIZE, PREFERENCE_DEFAULT_TEXT_SIZE);
mEditText.setTextSize(text_size * 1.25f);
-
}
@Override
@@ -698,6 +708,10 @@ private boolean getLocation() {
if (provider != null) {
final Location location = mLocationManager.getLastKnownLocation(provider);
+ if (location == null) {
+ mLocationManager.requestLocationUpdates(provider, 0, 0, this);
+ setSupportProgressBarIndeterminateVisibility(true);
+ }
mRecentLocation = location != null ? new ParcelableLocation(location) : null;
} else {
Toast.makeText(this, R.string.cannot_get_location, Toast.LENGTH_SHORT).show();
View
2  src/org/mariotaku/twidere/activity/DualPaneActivity.java
@@ -169,7 +169,7 @@ public final void showAtPane(final int pane, final Fragment fragment, final bool
if (addToBackStack) {
ft.addToBackStack(null);
}
- ft.setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
+ ft.setTransitionStyle(FragmentTransaction.TRANSIT_NONE);
ft.commit();
mDetailsFragment = fragment;
}
View
133 src/org/mariotaku/twidere/view/SlidePane.java
@@ -32,6 +32,9 @@
import android.view.ViewConfiguration;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
+import android.widget.Toast;
+import android.view.animation.TranslateAnimation;
+import android.view.animation.Animation;
public class SlidePane extends FrameLayout {
@@ -54,8 +57,9 @@ public SlidePane(Context context, AttributeSet attrs) {
public SlidePane(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- mInternalLinearLayout = new LinearLayout(context);
+ mInternalLinearLayout = new InternalLinearLayout(this);
setWillNotDraw(false);
+ setClipChildren(false);
final Resources res = getResources();
mShouldDisableScroll = res.getBoolean(R.bool.should_disable_scroll);
final LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(0, MATCH_PARENT, res.getInteger(R.integer.pane_right_shadow_weight));
@@ -76,92 +80,96 @@ public void addContent(View view, FrameLayout.LayoutParams params) {
mInternalContentView.addView(view, params);
}
- private Thread mThread;
-
void abortAnimation() {
- if (mThread != null) {
- mThread.interrupt();
- mThread = null;
+ final Animation scroll_anim = mInternalLinearLayout.getAnimation();
+ if (scroll_anim != null) {
+ scroll_anim.cancel();
}
}
void animateContentTo(final int x) {
if (shouldDisableScroll()) return;
abortAnimation();
- mThread = new AnimateScrollThread(x);
- mThread.start();
+ final int move = getContentScrollX() - x;
+ if (move == 0) return;
+ final TranslateAnimation anim = new TranslateAnimation(0, move, 0, 0);
+ anim.setDuration(100);
+ anim.setAnimationListener(new ScrollAnimationListener(x));
+ mInternalLinearLayout.startAnimation(anim);
+ }
+
+ class ScrollAnimationListener implements Animation.AnimationListener {
+
+ public void onAnimationStart(Animation anim) {
+ }
+
+ public void onAnimationEnd(Animation anim) {
+ post(new ScrollToRunnable());
+ }
+
+ public void onAnimationRepeat(Animation anim) {
+ }
+
+
+ private final int x;
+
+ ScrollAnimationListener(int x){
+ this.x = x;
+ }
+
+ class ScrollToRunnable implements Runnable {
+
+ public void run() {
+ scrollContentTo(x);
+ }
+
+ }
}
public void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if (mFirstCreate) {
- //closeNoAnimation();
post(new CloseNoAnimationRunnable());
mFirstCreate = false;
}
}
+ static class InternalLinearLayout extends LinearLayout {
+
+ private final SlidePane parent;
+
+ InternalLinearLayout(SlidePane parent) {
+ super(parent.getContext());
+ this.parent = parent;
+ }
+
+ public void onScrollChanged(int l, int t, int oldl, int oldt) {
+ super.onScrollChanged(l, t, oldl, oldt);
+ if (parent.shouldDisableScroll()) {
+ //parent.setBackgroundColor(Color.TRANSPARENT);
+ return;
+ }
+ final int max = parent.getMaxScrollWidth();
+ final float percent = (float)(limit(l + max, 0, max)) / max;
+ //parent.setBackgroundColor(Color.argb((int)(percent * 0x40), 0, 0, 0));
+ }
+
+ }
+
class CloseNoAnimationRunnable implements Runnable {
public void run() {
closeNoAnimation();
- }
-
-
+ }
}
boolean shouldDisableScroll() {
return mShouldDisableScroll;
}
- class AnimateScrollThread extends Thread {
-
- final int x;
-
- AnimateScrollThread(int x) {
- this.x = x;
- }
-
- public void run() {
- final int move = getContentScrollX() - x;
- if (move == 0) return;
- final int max = getMaxScrollWidth();
- final int step = (int) getResources().getDisplayMetrics().density * 16;
- try {
- int scroll = getContentScrollX();
- while (scroll >= -max && scroll <= 0) {
- scroll = getContentScrollX();
- post(new ScrollRunnable(limit(getContentScrollX() - (move > 0 ? step : -step), -max, 0)));
- Thread.sleep(1L);
- }
- } catch (InterruptedException e) {
-
- }
- }
-
- class ScrollRunnable implements Runnable {
-
- final int x;
-
- ScrollRunnable(final int x) {
- this.x = x;
- }
-
- public void run() {
- scrollContentTo(x);
- final int scroll = getContentScrollX();
- if (scroll == 0 || scroll == -getMaxScrollWidth()) {
- abortAnimation();
- }
- }
-
- }
- }
-
void scrollContentTo(int x) {
if (shouldDisableScroll()) return;
mInternalLinearLayout.scrollTo(x, 0);
- updateMainBackground();
}
int getContentScrollX() {
@@ -182,12 +190,13 @@ void setContentWidth(int width) {
void updateMainBackground() {
if (shouldDisableScroll()) {
- setBackgroundColor(Color.TRANSPARENT);
+ //setBackgroundColor(Color.TRANSPARENT);
return;
}
- final int sx = getContentScrollX();
- final float percent = (float)(limit(sx + getMaxScrollWidth(), 0, getMaxScrollWidth())) / getMaxScrollWidth();
- setBackgroundColor(Color.argb((int)(percent * 0x80), 0, 0, 0));
+ final int sx = getScrollX();
+ final int max = getMaxScrollWidth();
+ final float percent = (float)(limit(sx + max, 0, max)) / max;
+ //setBackgroundColor(Color.argb((int)(percent * 0x40), 0, 0, 0));
}
static class BlankView extends View {
@@ -197,7 +206,7 @@ void updateMainBackground() {
public BlankView(SlidePane parent) {
super(parent.getContext());
this.parent = parent;
- setBackgroundResource(R.drawable.two_panes_shadow_right);
+ setBackgroundResource(R.drawable.right_pane_shadow);
}
public void onSizeChanged(int w, int h, int oldw, int oldh) {
Please sign in to comment.
Something went wrong with that request. Please try again.