NekoX/TMessagesProj/src/main/java/org/telegram/ui/IdenticonActivity.java

167 lines
6.2 KiB
Java
Raw Normal View History

2013-10-25 17:19:00 +02:00
/*
2013-12-20 20:25:49 +01:00
* This is the source code of Telegram for Android v. 1.3.2.
2013-10-25 17:19:00 +02:00
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.ui;
import android.content.Context;
import android.os.Bundle;
2013-12-20 20:25:49 +01:00
import android.support.v7.app.ActionBar;
2013-10-25 17:19:00 +02:00
import android.text.Html;
import android.view.LayoutInflater;
2013-12-20 20:25:49 +01:00
import android.view.MenuItem;
2013-10-25 17:19:00 +02:00
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.TLRPC;
2013-10-25 17:19:00 +02:00
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.R;
2013-12-26 17:46:13 +01:00
import org.telegram.messenger.Utilities;
2013-10-25 17:19:00 +02:00
import org.telegram.ui.Views.BaseFragment;
import org.telegram.ui.Views.IdenticonView;
public class IdenticonActivity extends BaseFragment {
private int chat_id;
@Override
public boolean onFragmentCreate() {
chat_id = getArguments().getInt("chat_id");
return super.onFragmentCreate();
}
@Override
public void onFragmentDestroy() {
super.onFragmentDestroy();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (fragmentView == null) {
fragmentView = inflater.inflate(R.layout.identicon_layout, container, false);
IdenticonView identiconView = (IdenticonView) fragmentView.findViewById(R.id.identicon_view);
TextView textView = (TextView)fragmentView.findViewById(R.id.identicon_text);
TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().encryptedChats.get(chat_id);
2013-10-25 17:19:00 +02:00
if (encryptedChat != null) {
identiconView.setBytes(encryptedChat.auth_key);
TLRPC.User user = MessagesController.getInstance().users.get(encryptedChat.user_id);
textView.setText(Html.fromHtml(LocaleController.formatString("EncryptionKeyDescription", R.string.EncryptionKeyDescription, user.first_name, user.first_name)));
2013-10-25 17:19:00 +02:00
}
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}
@Override
public void applySelfActionBar() {
if (parentActivity == null) {
return;
}
ActionBar actionBar = parentActivity.getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowCustomEnabled(false);
actionBar.setSubtitle(null);
actionBar.setCustomView(null);
actionBar.setTitle(LocaleController.getString("EncryptionKey", R.string.EncryptionKey));
2013-10-25 17:19:00 +02:00
2013-12-20 20:25:49 +01:00
TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title);
2013-10-25 17:19:00 +02:00
if (title == null) {
final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android");
title = (TextView)parentActivity.findViewById(subtitleId);
}
if (title != null) {
2013-12-20 20:25:49 +01:00
title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_white, 0, 0, 0);
2013-12-26 17:46:13 +01:00
title.setCompoundDrawablePadding(Utilities.dp(4));
2013-10-25 17:19:00 +02:00
}
}
@Override
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
super.onConfigurationChanged(newConfig);
fixLayout();
}
@Override
public void onResume() {
super.onResume();
if (isFinish) {
return;
}
2013-12-20 20:25:49 +01:00
if (getActivity() == null) {
2013-10-25 17:19:00 +02:00
return;
}
((LaunchActivity)parentActivity).showActionBar();
((LaunchActivity)parentActivity).updateActionBar();
2013-10-25 17:19:00 +02:00
fixLayout();
}
private void fixLayout() {
final View v = getView();
if (v != null) {
ViewTreeObserver obs = v.getViewTreeObserver();
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
LinearLayout layout = (LinearLayout)fragmentView;
WindowManager manager = (WindowManager)parentActivity.getSystemService(Context.WINDOW_SERVICE);
2013-12-20 20:25:49 +01:00
int rotation = manager.getDefaultDisplay().getRotation();
2013-10-25 17:19:00 +02:00
if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
layout.setOrientation(LinearLayout.HORIZONTAL);
} else {
layout.setOrientation(LinearLayout.VERTICAL);
}
2013-12-20 20:25:49 +01:00
v.setPadding(v.getPaddingLeft(), 0, v.getPaddingRight(), v.getPaddingBottom());
2013-10-25 17:19:00 +02:00
v.getViewTreeObserver().removeOnPreDrawListener(this);
2013-12-20 20:25:49 +01:00
TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title);
2013-10-25 17:19:00 +02:00
if (title == null) {
2013-11-04 13:31:01 +01:00
final int subtitleId = ApplicationLoader.applicationContext.getResources().getIdentifier("action_bar_title", "id", "android");
2013-10-25 17:19:00 +02:00
title = (TextView)parentActivity.findViewById(subtitleId);
}
if (title != null) {
2013-12-20 20:25:49 +01:00
title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_white, 0, 0, 0);
2013-12-26 17:46:13 +01:00
title.setCompoundDrawablePadding(Utilities.dp(4));
2013-10-25 17:19:00 +02:00
}
return false;
}
});
}
}
@Override
2013-12-20 20:25:49 +01:00
public boolean onOptionsItemSelected(MenuItem item) {
2013-10-25 17:19:00 +02:00
int itemId = item.getItemId();
switch (itemId) {
case android.R.id.home:
finishFragment();
break;
}
return true;
}
}