Commit 1b53fd4c by german

Mensajes privados terminado con un AlertDialog

parent 296ba636
package com.yottacode.pictogram.tabletlibrary.gui.communicator; package com.yottacode.pictogram.tabletlibrary.gui.communicator;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.app.Fragment; import android.app.Fragment;
import android.provider.ContactsContract;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.yottacode.pictogram.tabletlibrary.R; import com.yottacode.pictogram.tabletlibrary.R;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
public class Message_Fragment extends Fragment { public class Message_Fragment extends Fragment {
LinearLayout layout = null;
ArrayList<ImageView> pictos = null;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_message, null); View v = inflater.inflate(R.layout.fragment_message, null);
Button button = (Button) v.findViewById(R.id.aceptar);
button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Log.i("TAG_PRUEBAS","Hace click");
// do something
getActivity().getFragmentManager().beginTransaction().remove(Message_Fragment.this).commit();
}
});
/*layout = (LinearLayout) v.findViewById(R.id.layoutImages);
pictos = new ArrayList<>();
for(int i = 0;i<layout.getChildCount();i++){
pictos.add((ImageView) layout.getChildAt(i));
}*/
// Inflate the layout for this fragment // Inflate the layout for this fragment
return v; return v;
} }
public boolean closedFragment(){ public void cargar_pictos(JSONArray arrayPictos){
this.onDestroy();
return true; for(int i = 0; i < arrayPictos.length(); i++) {
//ImageView imagen = (ImageView) layout.getChildAt(i);
JSONObject picto = null;
try {
picto = arrayPictos.getJSONObject(i).getJSONObject("attributes");
Log.i("TAG_PRUEBAS", "picto :" + i);
//pictos.get(i).setImageResource(R.drawable.anonymous_student);
//pictos.get(i).setImageURI(Uri.parse(picto.getString("uri")));
Log.i("TAG_PRUEBAS", "picto received:" + picto.getString("expression").toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
} }
} }
...@@ -3,6 +3,7 @@ package com.yottacode.pictogram.tabletlibrary.gui.communicator; ...@@ -3,6 +3,7 @@ package com.yottacode.pictogram.tabletlibrary.gui.communicator;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentManager; import android.app.FragmentManager;
import android.app.FragmentTransaction; import android.app.FragmentTransaction;
import android.content.ClipData; import android.content.ClipData;
...@@ -38,6 +39,8 @@ import android.widget.CheckBox; ...@@ -38,6 +39,8 @@ import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import android.widget.GridView; import android.widget.GridView;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.Toast; import android.widget.Toast;
...@@ -159,30 +162,55 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -159,30 +162,55 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
this.vocabulary = PCBcontext.getVocabulary(); this.vocabulary = PCBcontext.getVocabulary();
this.vocabulary.listen(PCBcontext.getRoom(), this, new ActionTalk.iActionListener() { this.vocabulary.listen(PCBcontext.getRoom(), this, new ActionTalk.iActionListener() {
@Override @Override
public void action(action action, int picto_cat, int picto_id, JSONObject msg) { public void action(action action, int picto_cat, int picto_id, JSONObject msg) {
Log.i(this.getClass().getCanonicalName(), action + " from " + picto_cat + "," + picto_id + " catched"); Log.i(this.getClass().getCanonicalName(), action + " from " + picto_cat + "," + picto_id + " catched");
if (action==ActionTalk.iActionListener.action.show) { if (action==ActionTalk.iActionListener.action.show) {
/* TODO: Para la siguiente version, codigo para mostrar los mensajes privados
Log.i("TAG_PRUEBAS","show message received:"+msg.toString());
JSONObject msg_attrs = null;
JSONArray pictos = null;
String mensaje= "";
try { try {
//Log.i("TAG_PRUEBAS","show message received:"+msg.get("expression")); msg_attrs = msg.getJSONObject("attributes");
JSONObject msg_attrs = msg.getJSONObject("attributes"); pictos = msg_attrs.getJSONArray("pictos");
JSONArray pictos = msg_attrs.getJSONArray("pictos");
for(int i = 0; i < pictos.length(); i++) { String user = pictos.getJSONObject(0).getJSONObject("attributes").getString("user_avatar");
JSONObject picto = pictos.getJSONObject(i).getJSONObject("attributes");
Log.i("TAG_PRUEBAS","picto received:"+picto.get("expression").toString()); if(user.equals(PCBcontext.getPcbdb().getCurrentUser().get_email_sup())){ //si el primer picto tiene ese sup asociado
mensaje += getResources().getString(R.string.message_from)+": "+PCBcontext.getPcbdb().getCurrentUser().get_name_stu()+", "+ PCBcontext.getPcbdb().getCurrentUser().get_surname_stu()+"\n";
mensaje += getResources().getString(R.string.says)+": ";
for(int i = 0; i < pictos.length(); i++) {
JSONObject picto = pictos.getJSONObject(i).getJSONObject("attributes");
mensaje += (i != pictos.length()-1 ? picto.get("expression").toString()+" - " : picto.get("expression").toString());
}
Log.i(LOG_TAG,"Mensaje: "+msg.toString());
final AlertDialog.Builder builder = new AlertDialog.Builder(PictogramActivity.this);
builder.setMessage(mensaje)
.setPositiveButton("Vale", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
// Create the AlertDialog object and return it
runOnUiThread(new Runnable() {
@Override
public void run() {
AlertDialog alert = builder.create();
alert.show();
}
});
} }
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Message_Fragment fragment = new Message_Fragment();
fragmentTransaction.add(R.id.fragment_container, fragment, "ALERTA");
fragmentTransaction.commit();
mainLayout.setEnabled(false); //Desactivar el fondo*/
} }
else if (PCBcontext.getPcbdb().getCurrentUser().is_mirror_on()) { else if (PCBcontext.getPcbdb().getCurrentUser().is_mirror_on()) {
......
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/serialmail" android:layout_below="@+id/serialmail"
android:layout_marginTop="25dp" android:layout_marginTop="25dp"
android:layout_toStartOf="@+id/imageView" android:layout_toStartOf="@+id/imageView1"
android:background="@drawable/edit_text_login_style" android:background="@drawable/edit_text_login_style"
android:fontFamily="monospace" android:fontFamily="monospace"
android:hint="@string/prompt_serial_pass" android:hint="@string/prompt_serial_pass"
...@@ -100,7 +100,7 @@ ...@@ -100,7 +100,7 @@
</LinearLayout> </LinearLayout>
<ImageView <ImageView
android:id="@+id/imageView" android:id="@+id/imageView1"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="end" android:layout_gravity="end"
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
android:contentDescription="@string/app_name" android:contentDescription="@string/app_name"
android:orientation="vertical" android:orientation="vertical"
android:src="@drawable/pictogram_logo" android:src="@drawable/pictogram_logo"
android:id="@+id/imageView" android:id="@+id/imageView1"
android:scaleX="1.5" android:scaleX="1.5"
android:scaleY="1.5" android:scaleY="1.5"
android:layout_centerVertical="true" android:layout_centerVertical="true"
......
...@@ -27,48 +27,49 @@ ...@@ -27,48 +27,49 @@
android:textStyle="bold" /> android:textStyle="bold" />
<LinearLayout <LinearLayout
android:id="@+id/layoutImages"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <ImageView
android:id="@+id/imageView" android:id="@+id/imageView1"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" /> android:layout_marginRight="5dp" />
<ImageView <ImageView
android:id="@+id/imageView5" android:id="@+id/imageView2"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" /> android:layout_marginRight="5dp" />
<ImageView <ImageView
android:id="@+id/imageView4" android:id="@+id/imageView3"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" /> android:layout_marginRight="5dp" />
<ImageView <ImageView
android:id="@+id/imageView3" android:id="@+id/imageView4"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" /> android:layout_marginRight="5dp" />
<ImageView <ImageView
android:id="@+id/imageView2" android:id="@+id/imageView5"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" /> android:layout_marginRight="5dp" />
<ImageView <ImageView
android:id="@+id/imageView8" android:id="@+id/imageView6"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
...@@ -84,20 +85,20 @@ ...@@ -84,20 +85,20 @@
android:layout_weight="1" /> android:layout_weight="1" />
<ImageView <ImageView
android:id="@+id/imageView6" android:id="@+id/imageView8"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" android:layout_marginRight="5dp"
android:layout_weight="1" /> android:layout_weight="1" />
</LinearLayout> </LinearLayout>
<Button <Button
android:id="@+id/aceptar" android:id="@+id/aceptar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Button" android:text="Vale" />
android:onClick="closedFragment()"/>
</LinearLayout> </LinearLayout>
......
...@@ -48,6 +48,8 @@ ...@@ -48,6 +48,8 @@
<string name="titleCropperNew">New Picto</string> <string name="titleCropperNew">New Picto</string>
<string name="insertPasswordLogin">Insert Password</string> <string name="insertPasswordLogin">Insert Password</string>
<string name="version_label">Version:</string> <string name="version_label">Version:</string>
<string name="message_from">Message from</string>
<string name="says">Says</string>
</resources> </resources>
...@@ -47,6 +47,8 @@ ...@@ -47,6 +47,8 @@
<string name="titleCropperNew">Nuevo Pictograma</string> <string name="titleCropperNew">Nuevo Pictograma</string>
<string name="insertPasswordLogin">Inserte Contraseña</string> <string name="insertPasswordLogin">Inserte Contraseña</string>
<string name="version_label">Versión:</string> <string name="version_label">Versión:</string>
<string name="message_from">Mensaje de</string>
<string name="says">Dice</string>
</resources> </resources>
...@@ -54,4 +54,6 @@ ...@@ -54,4 +54,6 @@
<!-- TODO: Remove or change this placeholder text --> <!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string> <string name="hello_blank_fragment">Hello blank fragment</string>
<string name="message_from">Mensaje de</string>
<string name="says">Dice</string>
</resources> </resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment