/*
Swisscom Safe Connect
Copyright (C) 2014 Swisscom
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.swisscom.safeconnect.activity;
import android.content.Intent;
import android.graphics.Matrix;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.swisscom.safeconnect.R;
import com.swisscom.safeconnect.utils.Config;
public class TermsPreviewActivity extends PipeActivity {
private Button btnAcceptTerms;
private TextView tvOpenTerms;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.terms_preview);
tvOpenTerms = (TextView) findViewById(R.id.tv_open_terms);
tvOpenTerms.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(TermsPreviewActivity.this, TermsActivity.class));
}
});
btnAcceptTerms = (Button) findViewById(R.id.but_accept_terms);
btnAcceptTerms.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// if users clicks, he accepts the terms
Config.getInstance().setTermsAccepted(true);
startActivity(new Intent(TermsPreviewActivity.this, RegistrationActivity.class));
finish();
}
});
final ImageView bv = (ImageView) findViewById(R.id.textureImageView);
bv.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@SuppressWarnings("deprecation")
@Override
public void onGlobalLayout() {
if (bv.getDrawable() == null) {
return;
}
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
bv.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
bv.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
float verticalScalingFactor = (float)bv.getHeight() / bv.getDrawable().getIntrinsicHeight();
float horizontalScalingFactor = 2f * bv.getWidth() / bv.getDrawable().getIntrinsicWidth();
Matrix matrix = new Matrix();
matrix.setTranslate(bv.getWidth() - bv.getDrawable().getIntrinsicWidth(), 0);
matrix.postScale(horizontalScalingFactor, verticalScalingFactor, bv.getWidth(), 0);
bv.setImageMatrix(matrix);
}
});
}
}