Merge branch 'dev'

This commit is contained in:
DrKLO 2014-03-23 16:12:45 +04:00
commit e7e0e67d51
7 changed files with 121 additions and 41 deletions

View File

@ -82,7 +82,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 207
versionName "1.4.6"
versionCode 208
versionName "1.4.7"
}
}

View File

@ -75,6 +75,9 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
public final static int audioProgressDidChanged = 50001;
public final static int audioDidReset = 50002;
public final static int recordProgressChanged = 50003;
public final static int recordStarted = 50004;
public final static int recordStartError = 50005;
public final static int recordStopped = 50006;
private HashMap<String, ArrayList<WeakReference<FileDownloadProgressListener>>> loadingFileObservers = new HashMap<String, ArrayList<WeakReference<FileDownloadProgressListener>>>();
private HashMap<Integer, String> observersByTag = new HashMap<Integer, String>();
@ -782,10 +785,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
return isPaused;
}
public boolean startRecording(final long dialog_id) {
final Semaphore semaphore = new Semaphore(0);
final Boolean[] result = new Boolean[1];
public void startRecording(final long dialog_id) {
try {
Vibrator v = (Vibrator) ApplicationLoader.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(20);
@ -797,8 +797,12 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
@Override
public void run() {
if (audioRecorder != null) {
result[0] = false;
semaphore.release();
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(recordStartError);
}
});
return;
}
@ -813,8 +817,12 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
try {
if (startRecord(recordingAudioFile.getAbsolutePath()) == 0) {
result[0] = false;
semaphore.release();
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(recordStartError);
}
});
return;
}
audioRecorder = new AudioRecord(MediaRecorder.AudioSource.MIC, 16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, recordBufferSize * 10);
@ -870,22 +878,24 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
}
result[0] = false;
semaphore.release();
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(recordStartError);
}
});
return;
}
recordQueue.postRunnable(recordRunnable);
result[0] = true;
semaphore.release();
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(recordStarted);
}
});
}
}, 120);
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return result[0];
});
}
private void stopRecordingInternal(final boolean send) {
@ -963,6 +973,12 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
} catch (Exception e) {
FileLog.e("tmessages", e);
}
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(recordStopped);
}
});
}
});
}

View File

@ -34,6 +34,8 @@ import android.support.v7.app.ActionBarActivity;
import android.text.Html;
import android.util.SparseArray;
import org.json.JSONArray;
import org.json.JSONObject;
import org.telegram.objects.MessageObject;
import org.telegram.objects.PhotoObject;
import org.telegram.ui.LaunchActivity;
@ -4516,6 +4518,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
try {
mNotificationManager.notify(1, notification);
if (preferences.getBoolean("EnablePebbleNotifications", false)) {
sendAlertToPebble(msg);
}
currentPushMessage = messageObject;
} catch (Exception e) {
FileLog.e("tmessages", e);
@ -4523,6 +4528,26 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
public void sendAlertToPebble(String message) {
try {
final Intent i = new Intent("com.getpebble.action.SEND_NOTIFICATION");
final HashMap<String, String> data = new HashMap<String, String>();
data.put("title", LocaleController.getString("AppName", R.string.AppName));
data.put("body", message);
final JSONObject jsonData = new JSONObject(data);
final String notificationData = new JSONArray().put(jsonData).toString();
i.putExtra("messageType", "PEBBLE_ALERT");
i.putExtra("sender", "MyAndroidApp");
i.putExtra("notificationData", notificationData);
ApplicationLoader.applicationContext.sendBroadcast(i);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
public void dialogsUnreadCountIncr(final HashMap<Long, Integer> values) {
Utilities.RunOnUIThread(new Runnable() {
@Override

View File

@ -33,10 +33,12 @@ public class NativeLoader {
try {
String folder = null;
long libSize = 0;
long libSize2 = 0;
if (Build.CPU_ABI.equalsIgnoreCase("armeabi-v7a")) {
folder = "armeabi-v7a";
libSize = sizes[1];
libSize2 = sizes[0];
} else if (Build.CPU_ABI.equalsIgnoreCase("armeabi")) {
folder = "armeabi";
libSize = sizes[0];
@ -53,10 +55,14 @@ public class NativeLoader {
}
File destFile = new File(context.getApplicationInfo().nativeLibraryDir + "/libtmessages.so");
if (destFile.exists() && destFile.length() == libSize) {
if (destFile.exists() && (destFile.length() == libSize || libSize2 != 0 && destFile.length() == libSize2)) {
Log.d("tmessages", "Load normal lib");
System.loadLibrary("tmessages");
return;
try {
System.loadLibrary("tmessages");
return;
} catch (Exception e) {
e.printStackTrace();
}
}
File destLocalFile = new File(context.getFilesDir().getAbsolutePath() + "/libtmessages.so");
@ -64,6 +70,7 @@ public class NativeLoader {
if (destLocalFile.length() == libSize) {
Log.d("tmessages", "Load local lib");
System.load(destLocalFile.getAbsolutePath());
return;
} else {
destLocalFile.delete();
}

View File

@ -342,6 +342,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
NotificationCenter.getInstance().addObserver(this, MediaController.audioProgressDidChanged);
NotificationCenter.getInstance().addObserver(this, MediaController.audioDidReset);
NotificationCenter.getInstance().addObserver(this, MediaController.recordProgressChanged);
NotificationCenter.getInstance().addObserver(this, MediaController.recordStarted);
NotificationCenter.getInstance().addObserver(this, MediaController.recordStartError);
NotificationCenter.getInstance().addObserver(this, MediaController.recordStopped);
NotificationCenter.getInstance().addObserver(this, 997);
loading = true;
@ -388,6 +391,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
NotificationCenter.getInstance().removeObserver(this, MediaController.audioProgressDidChanged);
NotificationCenter.getInstance().removeObserver(this, MediaController.audioDidReset);
NotificationCenter.getInstance().removeObserver(this, MediaController.recordProgressChanged);
NotificationCenter.getInstance().removeObserver(this, MediaController.recordStarted);
NotificationCenter.getInstance().removeObserver(this, MediaController.recordStartError);
NotificationCenter.getInstance().removeObserver(this, MediaController.recordStopped);
NotificationCenter.getInstance().removeObserver(this, 997);
if (sizeNotifierRelativeLayout != null) {
sizeNotifierRelativeLayout.delegate = null;
@ -405,6 +411,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (mWakeLock != null) {
try {
mWakeLock.release();
mWakeLock = null;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@ -677,15 +684,13 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
startedDraggingX = -1;
recordingAudio = MediaController.getInstance().startRecording(dialog_id);
MediaController.getInstance().startRecording(dialog_id);
updateAudioRecordIntefrace();
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
startedDraggingX = -1;
if (recordingAudio) {
MediaController.getInstance().stopRecording(true);
recordingAudio = false;
updateAudioRecordIntefrace();
}
MediaController.getInstance().stopRecording(true);
recordingAudio = false;
updateAudioRecordIntefrace();
} else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE && recordingAudio) {
float x = motionEvent.getX();
if (x < -distCanMove) {
@ -885,9 +890,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
if (recordingAudio) {
try {
PowerManager pm = (PowerManager)parentActivity.getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "audio record lock");
mWakeLock.acquire();
if (mWakeLock == null) {
PowerManager pm = (PowerManager) parentActivity.getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "audio record lock");
mWakeLock.acquire();
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@ -936,6 +943,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (mWakeLock != null) {
try {
mWakeLock.release();
mWakeLock = null;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@ -2229,6 +2237,16 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
mActionMode.finish();
mActionMode = null;
}
} else if (id == MediaController.recordStartError || id == MediaController.recordStopped) {
if (recordingAudio) {
recordingAudio = false;
updateAudioRecordIntefrace();
}
} else if (id == MediaController.recordStarted) {
if (!recordingAudio) {
recordingAudio = true;
updateAudioRecordIntefrace();
}
}
}

View File

@ -141,7 +141,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else if (i == 17) {
} else if (i == 19) {
if (reseting) {
return;
}
@ -202,6 +202,13 @@ public class SettingsNotificationsActivity extends BaseFragment {
editor.putBoolean("EnableContactJoined", !enabled);
editor.commit();
listView.invalidateViews();
} else if (i == 17) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
boolean enabled = preferences.getBoolean("EnablePebbleNotifications", false);
editor.putBoolean("EnablePebbleNotifications", !enabled);
editor.commit();
listView.invalidateViews();
}
}
});
@ -334,15 +341,15 @@ public class SettingsNotificationsActivity extends BaseFragment {
public boolean isEnabled(int i) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
boolean enabledAll = preferences.getBoolean("EnableAll", true);
if (i == 17 || i == 15) {
if (i == 19 || i == 15) {
return true;
}
return !(i != 1 && !enabledAll && i != 13) && (i > 0 && i < 5 || i > 5 && i < 10 || i > 10 && i < 14);
return !(i != 1 && !enabledAll && i != 13) && (i > 0 && i < 5 || i > 5 && i < 10 || i > 10 && i < 14) || i == 17;
}
@Override
public int getCount() {
return 18;
return 20;
}
@Override
@ -378,6 +385,8 @@ public class SettingsNotificationsActivity extends BaseFragment {
} else if (i == 14) {
textView.setText(LocaleController.getString("Events", R.string.Events));
} else if (i == 16) {
textView.setText(LocaleController.getString("Pebble", R.string.Pebble));
} else if (i == 18) {
textView.setText(LocaleController.getString("Reset", R.string.Reset));
}
} if (type == 1) {
@ -433,6 +442,10 @@ public class SettingsNotificationsActivity extends BaseFragment {
enabled = preferences.getBoolean("EnableContactJoined", true);
textView.setText(LocaleController.getString("ContactJoined", R.string.ContactJoined));
divider.setVisibility(View.INVISIBLE);
} else if (i == 17) {
enabled = preferences.getBoolean("EnablePebbleNotifications", false);
textView.setText(LocaleController.getString("Alert", R.string.Alert));
divider.setVisibility(View.INVISIBLE);
}
if (enabled) {
checkButton.setImageResource(R.drawable.btn_check_on);
@ -480,12 +493,12 @@ public class SettingsNotificationsActivity extends BaseFragment {
}
textView.setText(LocaleController.getString("Sound", R.string.Sound));
divider.setVisibility(View.INVISIBLE);
} else if (i == 17) {
} else if (i == 19) {
textView.setText(LocaleController.getString("ResetAllNotifications", R.string.ResetAllNotifications));
textViewDetail.setText(LocaleController.getString("UndoAllCustom", R.string.UndoAllCustom));
divider.setVisibility(View.INVISIBLE);
}
if (i != 17 && !enabledAll) {
if (i != 19 && !enabledAll) {
view.setEnabled(false);
if(android.os.Build.VERSION.SDK_INT >= 11) {
textView.setAlpha(0.3f);
@ -507,9 +520,9 @@ public class SettingsNotificationsActivity extends BaseFragment {
@Override
public int getItemViewType(int i) {
if (i == 0 || i == 5 || i == 10 || i == 14 || i == 16) {
if (i == 0 || i == 5 || i == 10 || i == 14 || i == 16 || i == 18) {
return 0;
} else if (i > 0 && i < 4 || i > 5 && i < 9 || i > 10 && i < 14 || i == 15) {
} else if (i > 0 && i < 4 || i > 5 && i < 9 || i > 10 && i < 14 || i == 15 || i == 17) {
return 1;
} else {
return 2;

View File

@ -249,6 +249,7 @@
<string name="AutomaticPhotoDownloadPrivateChats">Private Chats</string>
<string name="Events">EVENTS</string>
<string name="ContactJoined">Contact joined Telegram</string>
<string name="Pebble">PEBBLE</string>
<!--media view-->
<string name="NoMedia">No shared media yet</string>